I have an undocumented web service and I need to get the version of this web service by using client written in Visual C#. Problem is that I'm too much of a noob.
I have added the Service Reference in Visual Studio so I got a proxy file and the output.config file.
I get this row from VS to start a new instance of the class:
DentalScannerServiceClient client = new DentalScannerServiceClient();
So I put this in my console app:
DentalScannerServiceClient client = new DentalScannerServiceClient();
client.GetSoftwareVersion();
Get the error "No overload for method 'GetSoftwareVersion' takes 0 arguments".
Intelisens tells me this when i start typing client.GetSoftwareVersion:
Status DentalScannerServiceClient.GetSoftwareVersion(out string version)
So I try this code:
DentalScannerServiceClient client = new DentalScannerServiceClient();
string oo;
client.GetSoftwareVersion(out oo);
And then print the string but when I run the code I get this error:
"InvalidOperationException was unhandled"
"Could not find default endpoint element that references contract 'IDentalScannerService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."
Any ideas how to solve this or where to start looking? I am thankful for any help. Maybe it is something simple. I little experience with C# as well.
app.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="ThisIsTest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><applicationSettings>
<ThisIsTest.Properties.Settings>
<setting name="ThisIsTest_localhost_DentalScannerService" serializeAs="String">
<value>http://localhost:8731/DentalServiceLib/DentalScannerService/</value>
</setting>
</ThisIsTest.Properties.Settings>
</applicationSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8731/DentalServiceLib/DentalScannerService/"
binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"
contract="Scanner.IDentalScannerService" name="BasicEndPoint" />
</client>
</system.serviceModel>
</configuration>
output.config (got this from wsdl.exe, just did Project->Add Existing Item to add it:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8731/DentalServiceLib/DentalScannerService/"
binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"
contract="IDentalScannerService" name="BasicEndPoint" />
</client>
</system.serviceModel>
</configuration>
This is most likely due to the endpoint showing up in your config file more than once. Find the section <system.serviceModel><client></client></system.serviceModel> and check for duplicates (based on the name)
if the client section is not present in your config file at all you will need to add it.
follow this template
<configuration>
<system.serviceModel>
<client>
<endpoint address="<address here>" binding="basicHttpBinding" contract="<full qualifeid class name to client interface>" name="<some name here>" />
</client>
</system.serviceModel>
</configuration>
Since I could not get this method to work I did it another way:
Use the .wsdl file generated by wsdl.exe in the SDK
Downloaded soapUI and started a new project with the wsdl file as initial file
soapUI created SOAP requests for all the objects in the web service
Tested the different calls in soapUI and got response live
Went into C# VS and made my console app first start the web service and then send simple SOAP requests using HttpWebRequest
Bingo
This method works surprisingly well!
Related
I'm getting this error when trying to call a function of a wsdl. I added a ServiceReference to a project in my solution. In that project I have the following app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MYSERVICENAME_ws_Authorization_Binder" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="Basic"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="MYSERVICEURL"
binding="basicHttpBinding" bindingConfiguration="MYSERVICENAME_ws_Authorization_Binder"
contract="MYSERVICE.Authorization_PortType" name="MYSERVICENAME_ws_Authorization_Port" />
</client>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="messages"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\logs\messages.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="2000"/>
</diagnostics>
</system.serviceModel>
Then in my main project, the MVC project I have the following in the Web.config file.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MYSERVICENAME_ws_Authorization_Binder" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="MYSERVICEURL"
binding="basicHttpBinding" bindingConfiguration="MYSERVICENAME_ws_Authorization_Binder"
contract="MYSERVICE.Authorization_PortType" name="MYSERVICENAME_ws_Authorization_Port" />
</client>
</system.serviceModel>
The error occurs when I'm running in debug mode, localhost. I haven't tried it on my website since I'm still developing. My website has a certified SSL and my localhost is also configured to run on HTTPS but only with a self-signed certificate.
Am I getting this error because my self-signed certificate isn't enough? Can I make localhost also use the SSL that my website is using? If not, what's the best solution to this? I have found a few posts on this error but haven't found a solution that helps me yet.
I have the following Visual Studio Web application structure:
CustomerManagement\
- Services
- Customers.aspx
- Customers.aspx.cs
- CustomersWcfDS.svc
- Default.aspx
- web.config
The following code is inside the <configuration> in the web.config file:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICustomers" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1112/Services/Customers.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustomers" contract="CustomersService.ICustomers" name="BasicHttpBinding_ICustomers" />
</client>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
I build the project and enter the following URL but there is no reactions.
http://localhost:1112/Services/Customers.svc
I also tried the following:
http://localhost:1112/Services/CustomersWcfDS.svc
and also
http://localhost:1110/Services/Customers.svc
and
http://localhost:1110/Services/CustomersWcfDS.svc
(The port 1110 was tested because of the Project Properties Port number was set to 1110.)
but it still fail to display something similar like the following illustration
So, is there any expert that can advise me where have my WCF service URL gone to?
Hi based on your image,
I think you have renamed the service name as Customers.svc . But still it refering to the previous one. What you can do is try to find the "SimpleService.svc" in your entire solution
and rename it as Customers.svc. If you have any problem put it as a comment.
I have added a service reference named http://192.168.5.180:8080/intg/CrmWebService.asmx.
with name CrmWebProxy.
Below are the line of code.
Microsoft.Crm.Accelerator.Cca.SampleServices.CrmWebService.CustomerRecord[] resultWebService = new Microsoft.Crm.Accelerator.Cca.SampleServices.CrmWebService.CustomerRecord[3];
Microsoft.Crm.Accelerator.Cca.SampleServices.CrmWebService.CRMWebServiceSoapClient client = new Microsoft.Crm.Accelerator.Cca.SampleServices.CrmWebService.CRMWebServiceSoapClient();
resultWebService = client.GetCustomerData(firstName, lastName, phoneNumber, email, accountName, accountNo, maxRecords);
I get the above mentioned error.But if I test it in sample application it runs perfectly.
Any help.
It looks like you haven't copied the configuration entry for the web service. Without it, you cannot invoke a web service.
When you add a service reference in your project, configuration entry for your web service is added in your app.config of web.config file. A sample configuration may look like this. You need to copy that to your project configuration file.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="GlobalWeatherSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.webservicex.com/globalweather.asmx"
binding="basicHttpBinding" bindingConfiguration="GlobalWeatherSoap"
contract="ServiceReference1.GlobalWeatherSoap" name="GlobalWeatherSoap" />
</client>
</system.serviceModel>
</configuration>
Note: this is only a sample file. You need to find something like this from your project that works (in console) and copy that entry to the app.config in whatever other project you are using the service in.
I created a simple WCF web service that has one method: SubmitTicket(flightticket ft, string username, string password)
On the client side, I have an application for filling out a form (a flight ticket) and sending it to this newly created web service. When this flightticket object exceeds 8192bytes I get the following error:
"There was an error deserializing the object of type flightticket. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader"
I did some research online and found that I have to set the MaxStringContentLength in the web.config (server) and app.config (client) to a higher number. Problem is, I've tried every possible combination of settings in both config files from reading various blogs and sites, but it STILL fails on that same error!
I have attached my client and server config code (as it is at the moment, it has gone through many many many changes over the day with no success).
One thing I noticed is that the configuration.svcinfo file on my client application seems to always shows 8192 for MaxStringContentLength when I update the service reference. It appears to take all the default values even if I explicitly set the binding properties. Not sure if that is related to my problem at all, but worth mentioning.
Here is the applicable app.config/web.config code for defining the endpoint bindings:
<<<<< CLIENT >>>>>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFlightTicketWebService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://xx.xx.xx/xxxxxxxx.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFlightTicketWebService"
contract="FlightTicketWebService.IFlightTicketWebService"
name="BasicHttpBinding_IFlightTicketWebService" />
</client>
</system.serviceModel>
</configuration>
<<<<< SERVER >>>>>
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="GSH.FlightTicketWebService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<httpRuntime maxRequestLength="16384"/>
<compilation debug="true" targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFlightTicketWebService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 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 multipleSiteBindingsEnabled="true"/>
<services>
<service name="FlightTicketWebService">
<endpoint
name="FlightTicketWebServiceBinding"
address="http://xx.xx.xx/xxxxxxxxxxx.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IFlightTicketWebService"
contract="IFlightTicketWebService"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
I think the problem is that your service is not picking up its config because you have set the service name to be FlightTicketWebService whereas I would guess that the actual type is in a namespace. Fully qualify the service name with the namespace and it should pick up your config
Essentially this is a by-product of the WCF 4 default endpoint functionality that if it finds no matching config it puts endpoints up with the default config
This is the answer! I have searched everywhere the solution to this problem in WCF 4.0, and this entry by Richard Blewett was the final piece of the puzzle.
Key things learned from my research:
if the exception is thrown by the service, then only change the
Server Web.config file; don't worry about the client
create a custom basicHttpBinding:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="customBindingNameForLargeMessages">
add the larger readerQuota values (largest possible shown here, adjust to taste)
<binding name="customBindingNameForLargeMessages"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
create a service entry, with an endpoint that maps to the custom binding. The mapping happens when the endpoint's bindingConfiguration is the same as the binding's name:
Make sure the service name and the contract value are fully qualified - use the namespace, and the name of the class.
<system.serviceModel>
<services>
<service name="Namespace.ServiceClassName">
<endpoint
address="http://urlOfYourService"
bindingConfiguration="customBindingNameForLargeMessages"
contract="Namespace.ServiceInterfaceName"
binding="basicHttpBinding"
name="BasicHTTPEndpoint" />
</service>
</services>
Sorry for the repost but Im struggling to apply what I've read in the other posts to my problem.
I have a self hosted WCF service that runs fine when hosted on my machine and the client is on my machine.
I've tried to move the client to another machine and am now getting the "The caller was not authenticated by the service" error.
Please could someone advise on where the problem is occuring.
If you need anymore information please let me know.
Kind Regards
Ash
Here is the client config on my machine that works
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IDataCollector" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.1.74:8080/" binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IDataCollector" contract="AshService.IDataCollector"
name="WSDualHttpBinding_IDataCollector">
<identity>
<userPrincipalName value="Ash-PC\Ash" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Heres the server config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IDataCollector" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<services>
<service name="DataCollector">
<endpoint address="http://192.168.1.74:8080" binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IDataCollector" contract="IDataCollector" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
You are correct that your issues are due to Windows Authentication. As Rest Wing has described if you want to use AD credentials that the service has access to you will have to provide those credentials in order for the service to authenticate the client.
If you cannot use Windows authentication and you must authenticate the client you will need to look at other authentication techniques. One method is User Name/Password, but you will need to establish your own authentication algorithms. Another is certificates; the server and the client must have certificates installed (X509 certs work) to identify each other. There are other methods as well, but if I remember correctly only the above two will work with machines that are not in the same domain.
If you do not need to authenticate the client, set your security mode to "None". This would be a technique for publicly exposed services available over the internet.
You have differently configured bindings on client and service side.
Try using same binding configuration on both sides and see whether the exception is gone.
EDIT:
Credentials to be used for client authentication at service side must be provided as well.
// Provide client credentials
NetworkCredential credentials = new NetworkCredential( "UserName", "RealPasswordHere", "DomainOrMachineName" );
// Create factory that will be used to create proxy to the service
// Pass the client credentials into the factory
var factory = new ChannelFactory<AshService.IDataCollector>( "WSDualHttpBinding_IDataCollector" );
factory.Credentials.Windows.ClientCredential = credentials;
// Create and open proxy to the service
AshService.IDataCollector proxy = factory.CreateChannel();
( proxy as IChannel ).Open();
// Invoke an operation from the service
try this
svc.ClientCredentials.Windows.ClientCredential.UserName = "username";
svc.ClientCredentials.Windows.ClientCredential.Password = "password";