在 web.config 中添加第三个端点显示错误
Adding third endpoint in the web.config showing error
我是第一次使用 WCF 服务,当我添加 2 个端点时它工作正常并且在 web.config 中添加第三个端点时它显示以下错误
以下是我在web.config
中添加的服务
<services>
<service behaviorConfiguration="Default" name="WCFCurd.WCFContactService">
<endpoint address="contact" binding="basicHttpBinding" contract="WCFCurd.IWCFContact" />
<endpoint address="Calc" binding="basicHttpBinding" contract="WCFCurd.Ialc" />
<endpoint address="addition" binding="basicHttpBinding" contract="WCFCurd.Addition" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<!--<baseAddresses>
<add baseAddress="http://localhost:4072/WCFCurd"/>
</baseAddresses>-->
</host>
</service>
</services>
显示的错误是
Error: Cannot obtain Metadata from
http://localhost:4072/WCFContactService.svc If this is a Windows (R)
Communication Foundation service to which you have access, please
check that you have enabled metadata publishing at the specified
address. For help enabling metadata publishing, please refer to the
MSDN documentation at
http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange
Error URI: http://localhost:4072/WCFContactService.svc Metadata
contains a reference that cannot be resolved:
'http://localhost:4072/WCFContactService.svc'. There was no endpoint
listening at http://localhost:4072/WCFContactService.svc 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.HTTP GET Error URI:
http://localhost:4072/WCFContactService.svc There was an error
downloading 'http://localhost:4072/WCFContactService.svc'. The request
failed with the error message:-- Service
The service encountered an error.
An ExceptionDetail, likely created by
IncludeExceptionDetailInFaults=true, whose value
is:System.InvalidOperationException: An exception was thrown in a call
to a WSDL export extension:
System.ServiceModel.Description.DataContractSerializerOperationBehavior
当WCFContactService.scv 运行时不会,添加第三个端点时显示上述错误
enter image description here
下面你能理解的例子会对你有所帮助,试试这个例子
public int SimpleExample(<interface> Example1)
{
return Example1.ID;
}
public int SimpleExample1(<interface> Example2)
{
return Example2.ID;
}
public int SimpleExample2(<interface> Example3)
{
return Example3.ID;
}
public int SimpleExample3(<interface> Example4)
{
return Example4.ID;
}
public int SimpleExample4(<interface> Example5)
{
return Example5.ID;
}
public int SimpleExample5(<interface> Example6)
{
return Example6.ID;
}
.......
public int SimpleExampleN(<interface> ExampleN)
{
return ExampleN.ID;
}
我没有发现web.config中的上述代码有任何错误。这可能是由于函数名称或任何接口名称的冲突而发生的。
我是第一次使用 WCF 服务,当我添加 2 个端点时它工作正常并且在 web.config 中添加第三个端点时它显示以下错误
以下是我在web.config
中添加的服务 <services>
<service behaviorConfiguration="Default" name="WCFCurd.WCFContactService">
<endpoint address="contact" binding="basicHttpBinding" contract="WCFCurd.IWCFContact" />
<endpoint address="Calc" binding="basicHttpBinding" contract="WCFCurd.Ialc" />
<endpoint address="addition" binding="basicHttpBinding" contract="WCFCurd.Addition" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<!--<baseAddresses>
<add baseAddress="http://localhost:4072/WCFCurd"/>
</baseAddresses>-->
</host>
</service>
</services>
显示的错误是
Error: Cannot obtain Metadata from http://localhost:4072/WCFContactService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:4072/WCFContactService.svc Metadata contains a reference that cannot be resolved: 'http://localhost:4072/WCFContactService.svc'. There was no endpoint listening at http://localhost:4072/WCFContactService.svc 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.HTTP GET Error URI: http://localhost:4072/WCFContactService.svc There was an error downloading 'http://localhost:4072/WCFContactService.svc'. The request failed with the error message:-- Service
The service encountered an error.
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior
当WCFContactService.scv 运行时不会,添加第三个端点时显示上述错误
enter image description here
下面你能理解的例子会对你有所帮助,试试这个例子
public int SimpleExample(<interface> Example1)
{
return Example1.ID;
}
public int SimpleExample1(<interface> Example2)
{
return Example2.ID;
}
public int SimpleExample2(<interface> Example3)
{
return Example3.ID;
}
public int SimpleExample3(<interface> Example4)
{
return Example4.ID;
}
public int SimpleExample4(<interface> Example5)
{
return Example5.ID;
}
public int SimpleExample5(<interface> Example6)
{
return Example6.ID;
}
.......
public int SimpleExampleN(<interface> ExampleN)
{
return ExampleN.ID;
}
我没有发现web.config中的上述代码有任何错误。这可能是由于函数名称或任何接口名称的冲突而发生的。