Windows服务内托管的WCF服务的WSDL URL(basicHttpBinding)
时间:2020-03-06 15:05:11 来源:igfitidea点击:
我在其中一台服务器上的Windows服务中托管WCF服务。在basicHttpBinding中使其工作并在.NET中构建测试客户端(最终成功)之后,我继续尝试使用SoapClient类从PHP访问它。最终的使用者将是一个PHP网站,因此我需要在PHP中使其成为可消费的。
当我不得不在PHP代码的SoapClient类的构造函数中输入WSDL URL时,我感到很困惑。 WSDL在哪里?我所拥有的是:
http://172.27.7.123:8000/WordService和
http://172.27.7.123:8000/WordService/mex
这些都不是不公开WSDL的。
作为WCF的新手,我可能会问一个愚蠢的事情(或者我可能在某个地方有一个错误的假设)。请轻柔:D
而且不,http://172.27.7.123:8000/WordService?wsdl不会显示与http://172.27.7.123:8000/WordService不同的内容:((
我是否被迫将其托管在IIS中?我是否被迫使用常规的WebService?
解决方案
请查看此链接:
公开具有多个绑定和端点的WCF服务
Unlike previous ASMX services, the WSDL (web service definition language) for WCF services is not automatically generated. The previous image even tells us that "Metadata publishing for this service is currently disabled.". This is because we haven't configured our service to expose any meta data about it. To expose a WSDL for a service we need to configure our service to provide meta information. Note: The mexHttpBinding is also used to share meta information about a service. While the name isn't very "gump" it stands for Meta Data Exchange.
这可能会有所帮助:
http://msdn.microsoft.com/en-us/library/ms734765.aspx
简而言之,我们需要配置服务端点和行为。这是一个最小的示例:
<system.serviceModel> <services> <service <!-- Namespace.ServiceClass implementation --> name="WcfService1.Service1" <!-- User behaviour defined below --> behaviorConfiguration="SimpleServiceBehaviour"> <endpoint address="" binding="basicHttpBinding" <!-- Namespace.Interface that defines our service contract --> contract="WcfService1.IService1"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="SimpleServiceBehaviour"> <serviceMetadata <!-- We allow HTTP GET --> httpGetEnabled="true" <!-- Conform to WS-Policy 1.5 when generating metadata --> policyVersion="Policy15"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
不要忘记删除XML注释,因为它们在哪里无效。