[英]Web Service call error
I have created a WCF Service Reference from a provided WSDL file. 我已经从提供的WSDL文件创建了WCF服务参考。 in C# i've created an instance of the proxy client with a basic binding and called the required method: 在C#中,我创建了具有基本绑定的代理客户端实例,并调用了所需的方法:
public static bool main()
{
Debugger.Launch();
var binding = new BasicHttpsBinding();
binding.Security.Mode = BasicHttpsSecurityMode.Transport;
binding.TextEncoding = System.Text.Encoding.UTF8;
var remoteAddress = new System.ServiceModel.EndpointAddress("https://tester.mysite.de:8443/webservice/OrderNumber");
using (var orderNumberClient = new orderNumberClient(new System.ServiceModel.BasicHttpBinding(BasicHttpSecurityMode.Transport), remoteAddress))
{
string IDSystem = "123";
string IDOSystem = "abc";
//set timeout
orderNumberClient.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 10000);
orderNumberClient.ClientCredentials.UserName.UserName = "test";
orderNumberClient.ClientCredentials.UserName.Password = "test";
//call web service method
string productResponse = orderNumberClient.getNewOrderNumber(IDSystem, "01", IDOSystem); ;
MessageBox.Show(productResponse);
}
return true;
}
Unfortunately I'm receiving a fairly unhelpful error when i call the 'getNewOrderNumber' method: 不幸的是,当我调用“ getNewOrderNumber”方法时,我收到了一个无用的错误:
System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. System.Reflection.TargetInvocationException:Ein Aufrufziel发生异常。 ---> System.ServiceModel.FaultException: WebService processing Exception ---> System.ServiceModel.FaultException:Web服务处理异常
Server stack trace: 服务器堆栈跟踪:
bei System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) bei System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc&rpc)
bei System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) bei System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔型单向,ProxyOperationRuntime操作,Object [] ins,Object [] out,TimeSpan超时)
bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)
... ...
It's not an error on the web service side as that works fine in SOAPUI, am i possibly missing something in the binding? 这不是Web服务方面的错误,因为在SOAPUI中可以正常工作,我是否可能在绑定中缺少某些内容?
Hopefully someone more knowledgable on web-services can shine a light on the root cause. 希望对网络服务有更多了解的人可以阐明根本原因。
It turns out I wasn't sending the 'Authorization' header with the call. 事实证明,我没有随电话一起发送“ Authorization”标头。 To overcome the issue I used the OperationContextScope
class to add the required HttpRequestMessageProperty
to the proxy instances inner channel before making the actual web service method call: 为了克服该问题,在进行实际的Web服务方法调用之前,我使用了OperationContextScope
类将所需的HttpRequestMessageProperty
添加到代理实例内部通道:
using (OperationContextScope scope = new OperationContextScope(orderNumberClient.InnerChannel))
{
var httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " +
Convert.ToBase64String(Encoding.ASCII.GetBytes(orderNumberClient.ClientCredentials.UserName.UserName + ":" +
orderNumberClient.ClientCredentials.UserName.Password));
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
string Response = orderNumberClient.getNewOrderNumber(IDSystem, "01", IDOSystem);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.