I have created a WCF Service Reference from a provided WSDL file. in C# i've created an instance of the proxy client with a basic binding and called the required method:
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:
System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. ---> System.ServiceModel.FaultException: WebService processing Exception
Server stack trace:
bei System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
bei System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
...
It's not an error on the web service side as that works fine in SOAPUI, am i possibly missing something in the binding?
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. 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:
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.