WCF Web 服务更改 wsdl 名称和 targetNamespace [英] WCF Web Service change wsdl name and targetNamespace

查看:47
本文介绍了WCF Web 服务更改 wsdl 名称和 targetNamespace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,

我对基于 IIS 的 WCF 有点陌生,但之前做过一些 ASMX Web 服务.我的 WCF 服务已启动并正在运行,但 Web 服务为我生成的帮助程序页面具有默认名称,即该页面显示:

I'm a little new to WCF over IIS but have done some ASMX web services before. My WCF service is up and running but the helper page generated by the web service for me has the default names, i.e. the page that says:

您已经创建了一个服务.

You have created a service.

要测试此服务,您需要创建一个客户端并使用它来调用该服务.您可以使用以下语法从命令行使用 svcutil.exe 工具执行此操作:

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe http://localhost:53456/ServicesHost.svc?wsdl

svcutil.exe http://localhost:53456/ServicesHost.svc?wsdl

在标准的 ASMX 站点中,我将使用方法/类属性为 Web 服务提供名称和命名空间.当我点击 WSDL 的链接时:

In a standard ASMX site I would use method/class attributes to give the web service a name and a namespace. When I click on the link the WSDL has:

<wsdl:definitions name="SearchServices" targetNamespace="http://tempuri.org/" 

即不是我的界面中的 WCF 服务合同名称和命名空间.我假设 MEX 正在使用某种默认设置,但我想将它们更改为正确的名称.我该怎么做?

i.e. not the WCF Service Contract Name and Namespace from my Interface. I assume the MEX is using some kind of default settings but I'd like to change them to be the correct names. How can I do this?

推荐答案

将此添加到您的服务合同

Add this to your service contract

[ServiceContract(Namespace = "http://some.com/service/", Name = "ServiceName")]

将此添加到您的服务实现中

Add this to your service implementation

[ServiceBehavior(Namespace = "http://some.com/service/")]

将此添加到您的 web.config

Add this to your web.config

<endpoint binding="basicHttpBinding" bindingNamespace="http://myservice.com"....

这篇关于WCF Web 服务更改 wsdl 名称和 targetNamespace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆