Joa*_*Fdz 11 wcf binding tcp metadata
我花了几个小时来搜索这个错误,我几乎测试了它在Google上的所有内容.
我想在C#中使用TCP,.NET4和VS2010访问服务.
我有一个非常小的服务:
namespace WcfService_using_callbacks_via_tcp
{
[ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
public interface IService1
{
[OperationContract]
string Test(int value);
}
public interface ICallback
{
[OperationContract(IsOneWay = true)]
void ServerToClient(string sms);
}
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class Service1 : IService1
{
public string Test(int value)
{
ICallback the_callback = OperationContext.Current.GetCallbackChannel<ICallback>();
the_callback.ServerToClient("Callback from server, waiting 1s to return value.");
Thread.Sleep(1000);
return string.Format("You entered: {0}", value);
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用此Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfService_using_callbacks_via_tcp.Service1" behaviorConfiguration="Behaviour_Service1">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5050/Service1" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" bindingConfiguration="DuplexNetTcpBinding_IService1" contract="WcfService_using_callbacks_via_tcp.IService1"/>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="mexTcp" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<!--
TCP Binding
-->
<netTcpBinding>
<binding name="DuplexNetTcpBinding_IService1" sendTimeout="00:00:01"
portSharingEnabled="true">
</binding>
<binding name="mexTcp" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<!--
Behaviour to avoid a rush of clients and to expose metadata over tcp
-->
<behavior name="Behaviour_Service1">
<serviceThrottling maxConcurrentSessions="10000"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这个代码来托管它:
static void Main(string[] args)
{
Uri base_address = new Uri("net.tcp://localhost:5050/Service1");
ServiceHost host = null;
try
{
// Create the server
host = new ServiceHost(typeof(Service1), base_address);
// Start the server
host.Open();
// Notify it
Console.WriteLine("The service is ready at {0}", base_address);
// Allow close the server
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close it
host.Close();
}
catch (Exception ex)
{
// Opus an error occurred
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(string.Format("Host error:\r\n{0}:\r\n{1}", ex.GetType(), ex.Message));
Console.ReadLine();
}finally
{
// Correct memory clean
if(host != null)
((IDisposable)host).Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想创建客户端,但我不可能.我直接使用了Add Service Reference和svcutil,但是我收到了这个错误:
C:\ Program Files(x86)\ Microsoft Visual Studio 10.0\VC> svcutil.exe net.tcp:// loc alhost:5050/Service1 Microsoft(R)服务模型元数据工具[Microsoft(R)Windows(R)Communication Foundation ,版本4.0.30319.1]版权所有(c)Microsoft Corporation.版权所有.
尝试使用W S-Metadata Exchange从'net.tcp:// localhost:5050/Service1'下载元数据.此URL不支持DISCO.Microsoft(R)服务模型元数据工具[Microsoft(R)Windows(R)Communication Foundation,版本4.0.30319.1]版权所有(c)Microsoft Corporation.版权所有.
错误:无法从net.tcp:// localhost:5050/Service1获取元数据
如果这是您已加入的Windows(R)Communication Foundation服务,请检查您是否已在指定的地址启用了元数据发布.有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档 .
WS-Metadata Exchange错误URI:net.tcp:// localhost:5050/Service1
元数据包含无法解析的引用:'net.tcp:// localhost:5050/Service1'.
套接字连接已中止.这可能是由于错误处理您的消息或远程主机超出接收超时或未经过网络资源问题引起的.本地套接字超时为'00:04:59.9863281'.
Se ha forzadolaintercucióndeunaconexiónexistentepor el host remoto
如果您需要更多帮助,请输入"svcutil /?"
所以,我可以毫无问题地托管服务,但我无法创建代理.
我已经尝试了几乎所有我发现的配置,但我认为当前的web.config是正确的.使用mex的行为,安全性和绑定由端点使用.
我尝试创建app.config并使用svcutil.exe将其设置为同一文件夹.
您缺少服务配置
<system.serviceModel>
<services>
<service name="WcfService_using_callbacks_via_tcp.Service1"
behaviorConfiguration="Behavior_Service1">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5050/Service1" />
</baseAddresses>
</host>
<endpoint address="" contract="WcfService_using_callbacks_via_tcp.IService1"
binding="netTcpBinding" bindingConfiguration="DuplexNetTcpBinding_IService1" />
<endpoint address="mex" contract="IMetadataExchange" binding="mexTcpBindng" />
</service>
</services>
...
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
使用此配置,您不需要在代码中定义基址.
我在尝试更新现有服务引用时收到了相同的错误。事实证明,我在同一命名空间内具有相同名称的数据契约。进一步调查发现了真正的错误:
无法将类型[redacted]的 DataContract添加到 DataContractSet,因为名称空间“ [redacted] ”中具有相同数据协定名称“DocumentInfo”的类型“[redacted] ”已存在,并且协定不等效。
我更改了 DataContract 以提供其中一个类的名称。
[DataContract(Namespace = "urn:*[redacted]*:DataContracts", Name = "SC_DocumentInfo")]
Run Code Online (Sandbox Code Playgroud)
我将其发布在这里,以防它可以帮助遇到相同问题的人。
归档时间: |
|
查看次数: |
86149 次 |
最近记录: |