【发布时间】:2014-04-21 07:31:19
【问题描述】:
我在一个控制台应用程序中托管了多个 WCF 服务。它们都在代码中配置为使用带有 binding.TransferMode = TransferMode.Streamed 的 NetTcpBinding 消息合约用于定义它们的操作(详见下方代码)
- RequestMsgContract1,
- ResponseMsgContract1,
- ResponseMsgContract2
由于某种神秘的原因,我无法为使用的服务创建服务引用 ResponseMsgContract1 和 ResponceMsgContract2 消息同时收缩(参见下面的 IMyService1 定义)。我得到的消息是
URI 前缀无法识别。 元数据包含无法解析的引用:“net.tcp://localhost:8890/MyService1/mex”。 元数据包含无法解析的引用:“net.tcp://localhost:8890/MyService1/mex”。 如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。
创建仅使用 RequestMsgContract1 和 ResponseMsgContract2(请参阅 IMyService2)或仅使用 RequestMsgContract1、ResponseMsgContract1(请参阅 IMyService3)的其他两个服务的服务引用没有任何问题。
我的问题是我的消息合同出了什么问题,或者我应该在哪里寻找一些线索?
我没有在此处粘贴我的服务配置代码(正如我所说我不使用 xml 配置文件),因为它适用于三个服务中的两个。我认为错误的原因不存在,但您可以在这里找到服务主机控制台应用程序的完整代码http://pastebin.com/1THhc9mU
// Can't create service reference for this service
[ServiceContract]
interface IMyService1
{
[OperationContract]
ResponseMsgContract1 Operation1(RequestMsgContract1 arguments);
[OperationContract]
ResponceMsgContract2 Operation2();
}
// No problems with service reference creation for this one
[ServiceContract]
interface IMyService2
{
[OperationContract]
ResponceMsgContract2 Operation1();
[OperationContract]
ResponceMsgContract2 Operation2(RequestMsgContract1 arguments);
}
// No problems with service reference creation for this one
[ServiceContract]
interface IMyService3
{
[OperationContract]
ResponseMsgContract1 Operation1();
[OperationContract]
ResponseMsgContract1 Operation2(RequestMsgContract1 arguments);
}
他们使用这三个消息合约
[Serializable]
[MessageContract]
public class RequestMsgContract1
{
[MessageHeader(MustUnderstand = true)]
public Guid arg1;
}
[Serializable]
[MessageContract]
public class ResponseMsgContract1 : IDisposable
{
[MessageHeader(MustUnderstand = true)]
public long Length;
[MessageBodyMember(Order = 1)]
public System.IO.Stream stream;
public void Dispose()
{
if (stream != null)
{
stream.Close();
stream = null;
}
}
}
[Serializable]
[MessageContract]
public class ResponceMsgContract2 : IDisposable
{
[MessageHeader(MustUnderstand = true)]
public int Length { get; set; }
[MessageHeader(MustUnderstand = true)]
public string Str1 { get; set; }
[MessageBodyMember(Order = 1)]
public System.IO.Stream stream { get; set; }
public void Dispose()
{
if (stream != null)
{
stream.Close();
stream = null;
}
}
}
编辑: 如果在此处重现问题很重要,请使用我的 Visual Studio、.Net Framework 和 OS 版本
- Visual Studio 2012(11.0.61030.00 更新 4)
- .Net 框架版本 4.5.50709
- Windows 8 专业版
【问题讨论】:
-
我刚刚发现如果我将
ResponceMsgContract2.Length重命名为ResponceMsgContract2.Length2,创建服务引用的问题就会消失。但我还是不明白原因。 -
我在 MSDN 论坛上问过同样的问题。 link
标签: c# .net wcf visual-studio visual-studio-2012