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?
Related
I am developing system composed of WCF service and Xamarin.Forms client app. Seems like my application connects to server just fine (client has status Open when I check before invoking any methods), but after I try to invoke a service method, I am getting System.Net.WebException:
There was no endpoint listening at {0} that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
And the inner exception is:
System.Net.WebException: There was an error on processing web request: Status code 404(NotFound): Not Found
I can access service via web browsers on both pc and phone with address http://localhost:4408/DatabaseService.svc or http://192.168.8.106:4408/DatabaseService.svc but I get the exception when I am trying to invoke any methods from my app.
My client app is connecting to the host and invokes methods like this:
public App()
{
var binding = new BasicHttpBinding();
var timeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = timeout;
binding.ReceiveTimeout = timeout;
dbClient = new DatabaseServiceClient(binding, new EndpointAddress("http://192.168.8.106:4408/DatabaseService.svc"));
dbClient.Test();
}
My service is hosted by this simple program:
class Program
{
static void Main()
{
Uri baseAddress = new Uri("http://192.168.8.106:4408/DatabaseService.svc");
ServiceHost selfHost = new ServiceHost(typeof(DatabaseService.DatabaseService), baseAddress);
try
{
selfHost.AddServiceEndpoint(typeof(DatabaseService.IDatabaseService), new WSHttpBinding(), "DatabaseService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior
{
HttpGetEnabled = true
};
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();
Console.WriteLine("Host Status: " + selfHost.State);
Console.WriteLine("Host Addresses: " + selfHost.BaseAddresses.Count);
foreach (var x in selfHost.BaseAddresses)
Console.WriteLine(" - " + x.AbsoluteUri);
Console.WriteLine("<q to close >");
string command = "";
while (command != "q")
command = Console.ReadLine();
selfHost.Close();
Console.WriteLine("Host shutdown");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Exception thrown:\n" + e.Message);
Console.ReadLine();
selfHost.Abort();
}
}
}
Part of my applicationhost.config edited by me is:
<site name="OutdoorGame" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="F:\Studia\Magisterka\Github\Serwer\OutdoorGame\OutdoorGame" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:4408:localhost" />
<binding protocol="http" bindingInformation="*:4408:127.0.0.1" />
<binding protocol="http" bindingInformation="*:4408:192.168.8.106" />
</bindings>
</site>
I tried to stick to the tips included here: https://learn.microsoft.com/pl-pl/xamarin/xamarin-forms/data-cloud/web-services/wcf and I should also mention, that my services are working just fine, when accesed via ISS Express WCF Test Client.
I think I am missing something very simple but I have no clue what would it be. Any help will be much appreciated.
EDIT1
I probably should also show part of Web.config of the server:
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text"
textEncoding="utf-8"
useDefaultWebProxy="true"
allowCookies="false">
<security mode="Transport">
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="DatabaseService.DatabaseService">
<endpoint
address="http://192.168.8.106:4409/DatabaseService.svc"
binding="basicHttpBinding" bindingConfiguration="basicHttp"
contract="DatabaseService.IDatabaseService"/>
</service>
</services>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" bindingConfiguration="basicHttp"/>
</protocolMapping>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
</system.webServer>
If you have configured the endpoint information in the configuration file, you do not need to use the hosting program to configure the endpoint information. Moreover, if the project created using the WCF service application template does not require a program to host it, it can be directly deployed to IIS.
This project can be deployed directly to IIS or run directly in VS.
Secondly, I suggest you use Add Service Reference to generate the client:
Finally, you can directly call the service through the automatically generated proxy class.
Okey, so since I don't have much time, I basically gave up on this and just went to previous version of my project. Now my files look like this:
Connecting like this:
{
dbClient = new DatabaseServiceClient(new BasicHttpBinding(), new EndpointAddress("http://192.168.8.106:13409/DatabaseService.svc"));
}
applicationhost.config
<site name="DatabaseService" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="F:\Studia\Magisterka\Github\Serwer\OutdoorGame\DatabaseService" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:13409:localhost" />
<binding protocol="http" bindingInformation="*:13409:192.168.8.106" />
<binding protocol="http" bindingInformation="*:13409:127.0.0.1" />
</bindings>
</site>
My web.config is basically default.
Ports used are different because meanwhile I tried to create a new service (thought that could solve the problem) and that could be the thing.
Thanks to Ding Peng now I know, that I don't need service host, IIS Express is enough to host it.
Thanks guys for help.
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?
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.
I'm currently working on an integration with a leasing service provider, which runs (I assume) a Java service.
When I add the service reference in Visual Studio 2012, the reference is created correctly and I can call the methods specified in the service.
The problem arises when I get a response from the service.
Let's say I call the service with wrong parameters getCalculation and I get the JSON response JSONException. The problem is, that Visual Studio throws an exception There was an error reflecting 'JSONException'. and as InnerException: {"Namespace='http://service.ecommerce.cetelem.hu/' is not supported with rpc\\literal SOAP. The wrapper element has to be unqualified."}
This is the web.config code:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EcommerceServiceImplPortBinding">
<security mode="Transport" />
</binding>
<binding name="EcommerceServiceImplPortBinding1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://ecomdemo.cetelem.hu:443/ecommerce/EcommerceService"
binding="basicHttpBinding" bindingConfiguration="EcommerceServiceImplPortBinding"
contract="CetelemInstallmentsService.EcommerceService" name="EcommerceServiceImplPort" />
</client>
</system.serviceModel>
If this is of any help, I'm using WebAPI for the user "front-end".
Thank you for all the answers!
I figured this thing out eventually, but with the help of another post on SO: SOAP Requests in .net
All I needed to change in the service refence file was:
[System.ServiceModel.XmlSerializerFormatAttribute(Style = System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults = true)]
To:
[System.ServiceModel.XmlSerializerFormatAttribute(Style = System.ServiceModel.OperationFormatStyle.Document, SupportFaults = true)]
In one of my applications I am having issues connecting and authenticating a WCF service via the windows account. To test this I have moved it into a new solution with a simple console app and the standard WCF start application in VS2010.
WCF Code, for a simple action:
[PrincipalPermission(SecurityAction.Demand, Role = "xxxx\\xxxxxx")]
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
The configuration file:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:16674/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="testService.IService1"
name="BasicHttpBinding_IService1" />
</client>
And the call to this:
testService.Service1Client sv = new testService.Service1Client();
sv.GetData(1);
I'm getting the standard 'Request for principal permission failed.' error although I can't see how the config file is wrong. I've looked at the service object when it is being created and the ClientCredentials.Windows and username objects are null. Can anyone help me out, am I being stupid here?
Thanks
You need to set the credentials using code, see this article
testService.Service1Client sv = new testService.Service1Client();
sv.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultCredentials;
sv.GetData(1);