【发布时间】:2017-01-10 16:06:14
【问题描述】:
类定义如下:
public class BizTalkRESTTransmitHandler : IClientMessageInspector
我是一个带有这个签名的方法:
public object BeforeSendRequest(ref Message request, IClientChannel channel)
所以我认为我需要操作通道对象。
原因是在 BizTalk 2010 SendPort 中使用它来支持 JSON。 到目前为止我试过这个:
if (channel.RemoteAddress.Uri.AbsoluteUri == "http://api-stage2.mypartner.com/rest/events/2/"
|| channel.RemoteAddress.Uri.AbsoluteUri == "http://api.mypartner.com/rest/events/2/")
{
//TODO - "boxout" will become a variable obtained by parsing the message
Uri newUri = new Uri(channel.RemoteAddress.Uri.AbsoluteUri + "boxout");
channel.RemoteAddress.Uri = newUri;
}
上面给出了编译错误:“System.ServiceModel.EndpointAddress.Uri”不能分配给 - 它只准备好了“RemoteAddress 似乎也是只读的。
我已经引用了这些问题,但它们不使用通道对象。 Assign a URL to Url.AbsoluteUri in ASP.NET,和 WCF change endpoint address at runtime 但他们似乎没有处理通道对象。
更新 1:我尝试了以下方法:
//try create new channel to change URL
WebHttpBinding myBinding = new WebHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress(newURL);
ChannelFactory<IClientChannel> myChannelFactory = new ChannelFactory<IClientChannel>(myBinding, myEndpoint); //Change to you WCF interface
IClientChannel myNewChannel = myChannelFactory.CreateChannel();
channel = myNewChannel; //replace the channel parm passed to us
但它给出了这个错误: System.InvalidOperationException:尝试获取 IClientChannel 的合同类型,但该类型不是 ServiceContract,也不继承 ServiceContract。
【问题讨论】:
-
像这里这样创建一个全新的频道怎么样?好像有点矫枉过正。 stackoverflow.com/questions/27782919/…
标签: wcf c#-4.0 biztalk biztalk-2010