我有一个WCF服务,如果我在其中创建代理的项目(通过添加服务引用)与WCF服务在相同解决方案中,我可以为它创建代理
但是,如果我尝试在项目中添加服务引用,该项目与WCF服务(我确实运行)的解决方案不同,则无法找到端点。
有关元数据的消息说明,但我添加了以下暴露元数据的行为
<serviceMetadata httpGetEnabled="true" />
错误消息的详细信息如下:
There was an error downloading 'http://localhost:8112/LTA/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 405: Method Not Allowed.
Metadata contains a reference that cannot be resolved: 'http://localhost:8112/LTA'.
There was no endpoint listening at http://localhost:8112/LTA that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.
有谁知道问题是什么?整个ServiceModel元素是:
<system.serviceModel>
<services>
<service name="WCFLicenceService.LicenceTrackerService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8112" />
</baseAddresses>
</host>
<endpoint address="LTS" binding="basicHttpBinding" contract="WCFLicenceService.ILicenceTrackerService" />
<endpoint
address="net.tcp://localhost:8113/LTS"
binding ="netTcpBinding"
contract="WCFLicenceService.ILicenceTrackerService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
答案 0 :(得分:2)
正如您所见,服务引用是针对必须存在的http://localhost:8112/LTA/_vti_bin/ListData.svc/$metadata
创建的。如果Web服务项目位于同一个Sln中,VS IDE可以通过在内置Web服务器(如IIS Express)上启动服务来为您执行技巧。如果服务项目位于另一个sln中,则必须在另一个VS IDE实例中运行该服务。
对于大型项目,以及其他VS解决方案中的许多其他项目所使用的Web服务,最好不要使用服务引用方法,而是可以为每个服务创建客户端API。客户端API可以分发给其他.NET项目。有关如何创建客户端API和各自优势的更多详细信息,请检查 WCF for the Real World, Not Hello World