Getting HTTPS to Work with WCF - c#

I am trying connect to wcf service. I dont have access to it. It has credentials and SSL (https).
try
{
var stub = new ServiceReference1.ServiceClient();
stub.ClientCredentials.UserName.UserName = "user";
stub.ClientCredentials.UserName.Password = "pass";
stub.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
stub.getData("Test");
}
catch (Exception ee)
{
}
app.config:
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService">
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://address/path/service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="ServiceReference1.IService" name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
Error I got:
An error occurred while making the HTTP request to https://address/path/Service.svc. This should be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.
What I am doing wrong??? Do I need something add to app.config?? I guess that something with certificate is not good???

Related

Issue with http request

I have an issue when I'm using webservice and when I try to access to some method I got this error:
An exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll but was not handled in user code
Additional information: An error occurred while making the HTTP request to https://flightxml.flightaware.com/soap/FlightXML2/op. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.
I call the web method like this
FlightXML2SoapClient client = new FlightXML2SoapClient();
client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;
string[] pm = client.AllAirports();
I've tried also with securityprotol(ssl3,tls11,tls12) but still nothing. I even tried with different versions of framework (5.0,6.0 and 7.0) and I got the same error.
My webconfig looks like this
</system.codedom>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="FlightXML2Soap">
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://flightxml.flightaware.com/soap/FlightXML2/op" binding="basicHttpBinding" bindingConfiguration="FlightXML2Soap" contract="FlightAwareXML.FlightXML2Soap" name="FlightXML2Soap"/>
</client>
</system.serviceModel>

Server Error is thrown when calling user defined HTTP binding to SAP PI

I have a code that calls SAP PI Webservice with the following config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="VMSUpdateVehicleMasterProcessing_Out_SyncBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
<binding name="VMSUpdateVehicleMasterProcessing_Out_SyncBinding1">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://gtsapgwqas.tmp.local:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=VMSPlantMaintenance_Q&receiverParty=&receiverService=&interface=VMSUpdateVehicleMasterProcessing_Out_Sync&interfaceNamespace=urn%3ATMP.com%3AERP%3APlantMaintenance%3ACreateUpdateVehicleMaster"
binding="basicHttpBinding" bindingConfiguration="VMSUpdateVehicleMasterProcessing_Out_SyncBinding"
contract="VMService.VMSUpdateVehicleMasterProcessing_Out_Sync"
name="HTTP_Port" />
</client>
</system.serviceModel>
</configuration>
To create an instance to use the method in this webservice, I just use:
VMService.VMSUpdateVehicleMasterProcessing_Out_SyncClient c = new VMSUpdateVehicleMasterProcessing_Out_SyncClient();
Then, when calling the method, I just use:
VehicleMasterResponse response = c.VMSUpdateVehicleMasterProcessing_Out_Sync(vm);
This works perfectly as I am able to pass updates and receive the appropriate response. My Problem is, I have to implement this in SSIS. SSIS does not recognize app.config so I tried to create my Basic HTTP Binding. Unfortunately, "Server Error" is always thrown when I call the well method...
Here is how I set up my binding and instance:
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
var addess = new EndpointAddress("http://gtsapgwqas.tmp.local:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=VMSPlantMaintenance_Q&receiverParty=&receiverService=&interface=VMSUpdateVehicleMasterProcessing_Out_Sync&interfaceNamespace=urn%3ATMP.com%3AERP%3APlantMaintenance%3ACreateUpdateVehicleMaster");
VMService.VMSUpdateVehicleMasterProcessing_Out_SyncClient c = new VMSUpdateVehicleMasterProcessing_Out_SyncClient(binding, addess);
c.ClientCredentials.UserName.UserName = "NAME";
c.ClientCredentials.UserName.Password = "PWORD";
Basically I just supplied the properties that is in the config file... What causes the Server Error and how to solve this problem?

wcf https with basic auth

I am trying to consume a service over https with basic auth.
Binding:
<bindings>
<wsHttpBinding>
<binding name="apiSoap11">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
<client>
<endpoint address="https://url"
binding="wsHttpBinding"
bindingConfiguration="apiSoap11"
contract="api"
name="apiSoap11" />
</client>
Code
var client = new Client();
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
var response = client.operation(request);
I am being returned a 500 error.
This request will works in SoapUi with basic auth and PasswordType ="PasswordText"
Any idea what I am missing.

C# WCF Service Result

The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm= Default Realm '.--The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm= Default Realm '.
Hi,
what is the meaning of the result which I mentioned above. I got this error message from one of services. It was working before I update the service reference.
You can see web.configuration belove
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MCCI_AR000001TR_Binding">
<security mode="Transport"/>
</binding>
</basicHttpBinding>
</bindings>
<client><endpoint address="https://ws.sagliknet.saglik.gov.tr/WSMuayene" binding="basicHttpBinding" bindingConfiguration="MCCI_AR000001TR_Binding" contract="MuayeneServiceReference.MCCI_AR000001TR_PortType" name="MCCI_AR000001TR_Port"/>
</client>
</system.serviceModel>
I assume you need to set the configuration as basic credential and you need also to pass you credential prior to create a channel.
<bindings>
<basicHttpBinding>
<binding name="MCCI_AR000001TR_Binding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
</bindings>

consuming web service in WPF

i want to use a web Service(WSDL) in my WPF App.
i have add it as a Service Reference to my app.
Code to call it is as :
ServiceReference1.WebService_ISB_SAB_Interface_ExtSoapClient soap =
new ServiceReference1.WebService_ISB_SAB_Interface_ExtSoapClient();
ServiceReference1.Request requestObj = new ServiceReference1.Request();
requestObj.UserID = "1001002_S1234534H";
requestObj.DomainName = "XXXX";
requestObj.MessageContent = "<PcpsChronicBalanceEnquiry>" +
"<Request>" +
"<PatientNric>S1234534H</PatientNric>" +
"<Year>2015</Year>" +
"<BillType>C</BillType>" +
"</PcpsChronicBalanceEnquiry>";
var ss = soap.Operation_1(requestObj);
But i dint get any response.
App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebService_ISB_SAB_Interface_ExtSoap">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
<binding name="WebService_ISB_SAB_Interface_ExtSoap1" />
<binding name="ISB_SAB_Orchestration_Orchestration_1_Port_SAB_RequestSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://u103-vw-bzap01.tst.cleo.sg:9320/ws/ISB_SAB_Interface_Ext_Proxy/ISB_SAB_Interface_Ext.asmx"
binding="basicHttpBinding" bindingConfiguration="WebService_ISB_SAB_Interface_ExtSoap"
contract="ServiceReference1.WebService_ISB_SAB_Interface_ExtSoap"
name="WebService_ISB_SAB_Interface_ExtSoap" />
<endpoint address="http://192.168.9.34/ISB_SAB_Interface_Proxy/ISB_SAB_Orchestration_Orchestration_1_Port_SAB_Request.asmx"
binding="basicHttpBinding" bindingConfiguration="ISB_SAB_Orchestration_Orchestration_1_Port_SAB_RequestSoap"
contract="ServiceReference2.ISB_SAB_Orchestration_Orchestration_1_Port_SAB_RequestSoap"
name="ISB_SAB_Orchestration_Orchestration_1_Port_SAB_RequestSoap" />
</client>
</system.serviceModel>
it throws exception as
"An unhandled exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in mscorlib.dll
Additional information: There was no endpoint listening at https://u103-vw-bzap01.tst.cleo.sg:9320/ws/ISB_SAB_Interface_Ext_Proxy/ISB_SAB_Interface_Ext.asmx that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."
Please help to resolve.

Categories