HTTP request is not allowed for client authentication scheme "Ntlm" - c#

I found this question, but it seems like not my way:(
I have client service (console app), and at server side- Bitrix CMS web-service.
So, all works well , but when i update service someday on my VS 2012 and
call Send(...) method- i got error:
Received from the server authentication header "NTLM". HTTP request is not allowed for client authentication scheme "Ntlm". Received from the server authentication header "NTLM".
(it is google translate)
I try to delete and recreate service, restart VS, restart Windows- it is not working.
So, app.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CTfsTasksWSBinding">
<security mode ="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://server.domen.local/tfs_tasks_ws.php"
binding="basicHttpBinding" bindingConfiguration="CTfsTasksWSBinding"
contract="Bitrix.CTfsTasksWSInterface" name="CTfsTasksWSSoap" />
</client>
</system.serviceModel>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source = |SQL/CE|" />
</connectionStrings>
</configuration>
So, my code:
Bitrix.CTfsTasksWSInterfaceClient cll = new Bitrix.CTfsTasksWSInterfaceClient();
cll.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(loginn, passwd);
cll.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
I create new simple console app and paste some code from main app- i have the same error.
Please help me to fix this problem.
Thank you.

I have not valid password.
All works.

Related

Cannot login Magento service using C# [Magento 1.9.3.3] Error: Premature end of data in tag html line 7

I'm developing a C# Winapp to communicate with the Magento Server. I'm trying to login into Magento service to add customer data but I can't get pass the login sequence.
This is my login code in C#
PortTypeClient mservice = new PortTypeClient();
string mlogin = mservice.login("user", "password");
And this is my app.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BTVBinding" maxReceivedMessageSize="2000000">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://admin.mywebsite.com/index.php/api/v2_soap/index"
binding="basicHttpBinding" bindingConfiguration="BTVBinding"
contract="BTVMagento.PortType" name="Port1" >
</endpoint>
</client>
</system.serviceModel>
I always got this error
System.ServiceModel.FaultException: 'SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://admin.mywebsite.com/index.php/api/v2_soap/index/?wsdl=1' : Premature end of data in tag html line 7
Found out the error caused by my endpoint redirected my API request to the website's homepage. The homepage's HTML code started at line 7 (Below 6 lines of comments). That's why it said Error: Premature end of data in tag html line 7.

How to get the correct ServiceReference and its endpoint-address for a WCF-Webservice on installation

I'm facing a problem going into the installation of a project of mine. It consists of three parts, a clientside WindowsForms-application, a WCF-Webservice and a Database (SQLExpress atm).
At the moment, the endpoint-address and service-reference needed for the connection between Client and Webservice are hardcoded into the app.config of the WindowsForms-Project, referencing the specific computer in the same network the Webservice is running on like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWemosService" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://ent-ga-04:8733/Design_Time_Addresses/WcfServiceWemos/WemosService/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWemosService"
contract="ServiceReferenceWemos.IWemosService" name="BasicHttpBinding_IWemosService" />
</client>
</system.serviceModel>
</configuration>
However, after installing client and Webservice on different devices, I'll have to change these values, of course, to match the new devices and connections. I just have no clue how to do so. Can you help me?
Okay, I found the answer by myself. Every C#-project comes with an appconfig, which, in the final version, is named [projectname].exe.config. The text inside is formatted like xml, so you can read, write and change its content. This way, you can change the endpoint, referencename etc.

Errors calling web service, " more than one endpoint configuration for that contract" or "no endpoint listening"

i just had a problem adding webservice that its solved in this thread
error on adding webservice
now i just have a problem by calling its method
this is my app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="sedardIPSoap" />
</basicHttpBinding>
<customBinding>
<binding name="sedardIPSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://service.proapp.ir/service/sedardIP.asmx"
binding="basicHttpBinding" bindingConfiguration="sedardIPSoap"
contract="sedardip_set.sedardIPSoap" name="sedardIPSoap" />
<endpoint address="http://service.proapp.ir/service/sedardIP.asmx"
binding="customBinding" bindingConfiguration="sedardIPSoap12"
contract="sedardip_set.sedardIPSoap" name="sedardIPSoap12" />
</client>
</system.serviceModel>
so when i try calling my function like this
sedardip_set.sedardIPSoapClient nm = new sedardip_set.sedardIPSoapClient();
nm.set_ip("x1", "x2", "x3");
it throws this exception
An endpoint configuration section for contract 'sedardip_set.sedardIPSoap'
could not be loaded because more than one endpoint configuration for that
contract was found. Please indicate the preferred endpoint configuration
section by name.
so i tried deleting one of the endpoints from app.config, after that it throws this exception
There was no endpoint listening at http://service.proapp.ir/service/sedardIP.asmx
that could accept the message. This is often caused by an incorrect address or
SOAP action. See InnerException, if present, for more details.
inner exception
{"The remote server returned an error: (404) Not Found."}
i just run service on my visual studio (locally) and by deleting second endpoint its just worked !
so can anyone plz help me to get this working on http://service.proapp.ir/service/sedardIP.asmx plz??
Is there a reason you need to use a web reference? A service reference is the updated, newer way of doing things, but if you need to use the web reference for some reason then that's fine too.
If you go the service reference route you can specifically name the endpoint you wish to use, for example:
sedardip_set.sedardIPSoapClient nm = new sedardip_set.sedardIPSoapClient("sedardIPSoap12");
nm.set_ip("x1", "x2", "x3");
It may have a new name after setting up the service reference but you would just substitute the new name in place of the sedardIPSoap12.

How to add custom security binding credentials to a web service reference?

I'm new to Service Reference stuff so I might need simple explanation.
I got a WSDL:
https://test.servicebench.com/servicebenchv5/services/CRMServiceOrderService?wsdl
I added the Service Reference in my project via MVS2013 without any problem.
Here's the autogenerated app.config file :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CRMServiceOrderBinding">
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint
address="https://test.servicebench.com/servicebenchv5/services/CRMServiceOrderService"
binding="customBinding"
bindingConfiguration="CRMServiceOrderBinding"
contract="ServiceBenchReference.CRMServiceOrderPortType"
name="CRMServiceOrderPort" />
</client>
</system.serviceModel>
</configuration>
Now, every requests I try to make to the server replies me : "Unauthorized".
I pretty sure it's because I didn't passed the required credentials in the SOAP request header.
I need to pass it 3 credentials (or info?) : ServiceBenchID, UserID and password.
I've tried using :
CRMServiceOrderPortTypeClient ServiceOrder = new CRMServiceOrderPortTypeClient();
ServiceOrder.ClientCredentials.UserName.UserName = myUserID;
ServiceOrder.ClientCredentials.UserName.password = myPassword;
but it didn't work. I checked the request via Fiddler and I didn't saw the credentials passed in the header.
So here's my question : How can I get these 3 custom credentials information to be passed in the header correctly ? (So I get a response from the server)
After searching a couple more hours, I manage to find a suitable solution !
Thanks to Thorarin for the piece of code,
How can I pass a username/password in the header to a SOAP WCF Service
It seems that having custom bindings in the app.config file is forcing you to add the security elements manually. I don't think its the best way to do it, but its working like this.

Empty soap:body when calling a web service from windows phone 8

I started from a WSDL file and I used the "Add Service Reference" capability to generate proxy classes. The server is Java/Axis.
I am using the following code:
MyServiceClient c = new MyServiceClient();
c.getVersionStringCompleted += new EventHandler<getVersionStringCompletedEventArgs>(MyCallBack);
var r = new getVersionStringRequest { };
c.getVersionStringAsync(r);
My Callback is really simple, just to verify at the beginning that the setup is OK.
static void MyCallBack(object sender, getVersionStringCompletedEventArgs e) {
Console.WriteLine("result {0}", e.ToString());
}
The endpoint is taken from the WSDL.
The server responds that there is no Body in the request.
What is wrong with my code? I am running Visual Studio 2013.
What is the correct way to access the service?
I am not sure if it needed however I am adding my conf file here:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyServiceSoapBinding" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://135.99.14.73:8081/axis/services/MyService"
binding="basicHttpBinding" bindingConfiguration="MyServiceSoapBinding"
contract="LoginReference.MyService" name="MyService" />
</client>
</system.serviceModel>
</configuration>
Try to use synchronous methods:
ChannelFactory<LoginReference.MyService> myChannelFactory = new ChannelFactory<LoginReference.MyService>("MyService");
// Create a channel.
LoginReference.MyService wcfClient1 = myChannelFactory.CreateChannel();
string s = wcfClient1.getVersionString();
Console.WriteLine(s);
((IClientChannel)wcfClient1).Close();
Do you have access to the service log? What does it say?
What does WCF test client tool say? Did you try to reach the service via Fiddler?

Categories