vs添加 wcf服务,普通的WebService服务,直接用WSHttpBinding就可以了;
可这次有个客户,不是WS,而是用的WebPost,而且添加服务引用,App.config无法自动生成(估计服务器配置有问题);
就给他们要了他们自己调用的代码,配置文件居然是自己手动写的。。。
1、发现behaviors里多了一个WebHttpBehavior,所以代码填上;
2、报错,"此工厂上启用了手动寻址,因此发送的所有消息都必须进行预寻址。"
网上查了下,发现 有个帖子说, 配置了 behaviorConfiguration="webBehavior" 就不会报错了。
所以,代码里,把 WSHttpBinding 改成 WebHttpBinding ,果然好了。
贴上代码:
string strWmsUrl = "http://xxx:xx/xxxx.svc";
//WSHttpBinding binding = new WSHttpBinding();
//binding.MaxReceivedMessageSize = int.MaxValue;
//binding.MaxBufferPoolSize = int.MaxValue;
WebHttpBinding binding = new WebHttpBinding();
binding.MaxReceivedMessageSize = int.MaxValue;
binding.MaxBufferPoolSize = int.MaxValue;
System.ServiceModel.EndpointAddress remoteAddress = new System.ServiceModel.EndpointAddress(new Uri(string.Format(strWmsUrl))); ;
DcServiceClient svProxy = new DcServiceClient(binding, remoteAddress);
svProxy.Endpoint.Behaviors.Add(new System.ServiceModel.Description.WebHttpBehavior());
WMS_U_VENDOR_INFORMATION paramDTO = new WMS_U_VENDOR_INFORMATION();
ResultMessage result = svProxy.AddVendorInfo(paramDTO);