WCF Test client showing 1 endpoint, while Config file exposing 3 endpoints - asp.net

I have a WCF web service with exposing 3 end points.
But when I debug it to WCF test client it is only showing one basicHttpBinding endpoint.
1 : Why so?
2 : Here I have one operation contract "CallADSWebMethod" which returns a DataContract (VINDescription)..Just curious to know..why this works great for me in real time but still it is not testable by test client..I mean Test client says "This operation is not supported by test client"
3 : Here in the endpointBehaviors - I have only given and no ...But still it is working from jquery ajax call..So what is the significance of "enableWebScript" ??
Config Info
<system.serviceModel>
<services>
<service behaviorConfiguration="asmx" name="ADSChromeVINDecoder.Service">
<endpoint address="basic"
binding="basicHttpBinding"
name="httpEndPoint"
contract="ADSChromeVINDecoder.IService"/>
<endpoint address="json"
binding="webHttpBinding"
behaviorConfiguration="webBehavior"
name="webEndPoint"
contract="ADSChromeVINDecoder.IService"/>
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="asmx">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>

The WCF Test Client will only show the SOAP endpoints - and there's only one of those (the one with the basicHttpBinding).
The json endpoint uses webHttpBinding (which is REST based - can't be tested by WCF Test Client)
The mex endpoint is the metadata exchange endpoint - not a real service endpoint.
Therefore, the WCF Test Client correctly show only one (SOAP) endpoint - there is only one!
Update: the WCF Test Client is rather limited, and one of the limits is that it cannot deal with your own custom datatypes as parameters. You can basically only test methods with parameters of type int, string, datetime and the like - the simplistic data types.
If you need more advanced web service testing, you should check out the (freely available) SoapUI tool for testing your SOAP web services - including complex parameter types and a lot more.

Related

Configure WCF with client certificate signing XMLDsig, WS-Security or XADES

Using VS2019, ASP.NET project running .net 4.0.
I created the soap client adding the Service Reference to the wsdl file. Now I'm configuring the certificate and calls method.
This way worked in the old soap server, but now the soap server changed. I tested with SoapUI using the same Basic Auth configuration and works perfectly, but not with my .Net 4.0 client...
Web.config
<system.serviceModel>
<bindings>
<customBinding>
<binding name="PLATAFORMA">
<textMessageEncoding messageVersion="Soap11WSAddressing10" />
<security
authenticationMode="MutualCertificateDuplex"
messageProtectionOrder="SignBeforeEncrypt"
messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<secureConversationBootstrap />
</security>
<httpsTransport />
</binding>
</customBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="CERT">
<clientCredentials>
<clientCertificate findValue="ClientCert" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
<serviceCertificate>
<defaultCertificate findValue="*.ServerCert.com" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint
address="endpointURI"
binding="customBinding"
bindingConfiguration="PLATAFORMA"
behaviorConfiguration="CERT"
contract="ServiceReference1.RequestPort1"
name="Request.Request1">
<identity>
<dns value="*.ServerCert.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
XML Outoing header (catched with intercerptor):
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<a:Action s:mustUnderstand="1">peticionSincrona</a:Action>
<a:MessageID>urn:uuid:e3a5c4bd-f159-48c1-8f3f-cf22da6b7e3b</a:MessageID>
<ActivityId CorrelationId="035f2491-0772-4b1e-a286-9be30720d5ea" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">4d7f76c2-0486-4a81-93ad-32aecf02b035</ActivityId>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo9ph/BcvvnBFuLQYdch+LyYAAAAAHsOKxYeqzk+Do5pQmamNIPUdiXOiYjpBl1dsV5pp+SMACQAA</VsDebuggerCausalityData>
</s:Header>
I understand that some information is needed, how can I specify to sign as XMLDsig? why is not soap/envelope/encoding? I need help to configure the soap client.
The server return error 500 with a default tomcat error, is not even soapenv:fault or similar. I think the request envelope is not generating properly.
EDIT: Must be over soap11
Is this the client configuration generated after changing the SOAP server? If it requires the Basic authentication, why do we not need to provide username/password, but just need to provide a client certificate(according to the binding type)?
I suggest you re-generate a client proxy class by adding service reference. this also generates a proper configuration in the webconfig file.
Besides, since the server changes, the server’s certificate used to implement HTTPS security may also change, so the default certificate we provide on the client-side should also be changed.
<serviceCertificate>
<defaultCertificate findValue="*.ServerCert.com" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
</serviceCertificate>
Mutual certificate authentication requires a trust relationship between the client and the server.
<security
authenticationMode="MutualCertificateDuplex"
Not only do we need to install a client certificate on the new server in order to trust the client, we also need to install the server’s certificate on the client-side.
For details,
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/message-security-with-a-certificate-client
Feel free to let me know if there is anything I can help with.

WCF configuration works on localhost, not on shared website

I have an old ASP.NET website that has a WCF service that is used to return a JSON payload. It works fine in localhost, but when I try to deploy it to a shared hosting website, I get an exception:
IIS specified authentication schemes 'IntegratedWindowsAuthentication, Basic, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.
I cannot make this change as it is a shared environment.
Is there something I need to change in my configuration in Web.config with regards to the service? Here's what I've got:
<system.serviceModel>
<services>
<service name="BoggleService">
<endpoint binding="webHttpBinding" contract="Solver" behaviorConfiguration="webHttp"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
I also had this configuration, but it was commented out (like I said, a project from long ago, trying to resurrect it):
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.example.com/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
But if I uncomment that and include it, I get the following exception in both localhost and in the shared hosting website:
Index was out of range. Must be non-negative and less than the size of the collection.
Here's the full stack trace:
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +64
System.ThrowHelper.ThrowArgumentOutOfRangeException() +15
System.Collections.Generic.List`1.get_Item(Int32 index) +7515544
System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage) +82
System.ServiceModel.Web.WebServiceHost.OnOpening() +203
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +229
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +121
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
[ServiceActivationException: The service '/Solver.svc' cannot be activated due to an exception during compilation. The exception message is: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index.]
System.ServiceModel.AsyncResult.End(IAsyncResult result) +11667006
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +275
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
And this is coming from within the bowels of WCF - it's not coming from my code (the stack trace shows it never gets to my code and if I run the debugger and set a breakpoint in my code, it is never reached).
And interestingly, if I set the <baseAddressPrefixFilters> setting to http://localhost, it works on localhost! But not on production.
Thanks!
I think the problem could be simplified given that it uses the WebHttpBinding to host Restful style service.
In .net4.5, we could use the following simplified configuration to host the Restful style service.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
By default, the webhttpbinding use WebHttpSecurityMode.None. So it is unlikely that the authentication schema error above will occur. If necessary, don't forget to enable the authentication mode in IIS authentication module.
Try to replace your configuration with mine and provide a http binding in IIS site binding module.
Feel free to let me know If there is anything I can help with.

WCF netTcpBinding: why can't I debug and why not stable?

I have created a WCF service hosted in an ASP.NET web application, with netTcpBinding. I want to make it run, but I'm always getting the "object not set to a reference"-error.
I first created my service and tested it using the default bindings. It worked, I got my expected results returned.
As I don't want to run it through http, but through tcp, I changed my bindings as follow:
<system.serviceModel>
<services>
<service name="be.xxx.xxx.WCF.Leasing">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="be.xxx.xxx.WCF.ILeasing" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/be.xxx.xxx.WCF/Leasing.svc"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
In the project properties, I've changed under the web tab that it should run under "Local IIS". Set the project URL to http://localhost/be.xxx.xxx.WCF and clicked the "Create Virtual Directory"-button.
I have also changed my IIS settings:
Application pool to .Net Framework v4.0.30319, Integrated
Under "Advanced Settings", I've added "net.tcp" for Enabled Protocols.
My Windows services "Net.Tcp Listener Adapter" and "Net.TCP Port Sharing Service" are both running.
I can browse to http://localhost/be.xxx.xxx.WCF/Leasing.svc, telling me that I have created a service.
So when I start debugging by hitting F5 (VS is running under administrator rights), I get the following screen:
OK, when I start the stand-alone WCF Test Client, and I reference to http://localhost/be.xxx.xxx.WCF/Leasing.svc/mex, it loads the functions:
First, it was totally giving me the nothing saying "Object reference not set to an instance of an object" exception.
Just while setting up this question, it ran, giving me back the expected results.
I couldn't believe why it ran this time, so I closed the WCF Test Client again, and retried my effort. Now it is giving me again the "Object reference not set to an instance of an object" exception.
I also tried adding the service reference to a test console application, but this is giving me the same problems.
So, why can't I debug in Visual Studio (~metdata not found), and why doesn't seem it to be stable (running once)?
Have you tried to define the http mex binding

How do I configure the type provided as the Service attribute value in web.config?

I have the following configured in my <system.serviceModel> tag of my web.config file:
<system.serviceModel>
<bindings/>
<client/>
<behaviors>
<serviceBehaviors>
<behavior name="serviceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="serviceTypeBehaviors" name="AcpService.MainFrameData">
<endpoint address="" binding="basicHttpBinding" contract="AcpService.IMainFrameService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
The XML of my service is this:
<%# ServiceHost Language="C#" Debug="true" Service="AcpService.MainFrameData" CodeBehind="MainFrameWoData.svc.cs" %>
My application is running in the Default Web Site's Application Pool with Enable 32-Bit Applications set to True (because the service uses some old data accessing libraries).
When I run it, I get this error:
Server Error in '/mainframe' Application.
The type 'AcpService.MainFrameData', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Exception Details: System.InvalidOperationException: The type 'AcpService.MainFrameData', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
I almost modified my <serviceHostingEnvironment> tag to include the <serviceActions> parameters, but I don't really understand how to do that.
This is how far I got:
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="~/mainframe/MainFrameWoData.svc"
service="AcpService.MainFrameData" />
</serviceActivations>
</serviceHostingEnvironment>
I'm not sure if I am doing this correctly, and I have no idea what to insert for the service= parameter. The info on MSDN seems useless.
This project originally had a different name, but I am having to add features to the service. I do not want to edit the active service, because doing so would mean all the employees trying to access the data on our internal network would be getting that error right now, so the service was copied to a new project, and it is being published to a new location on our server. My best guess is there is something in the web.config file (or ???) that does not match up to something the project itself.
Could someone give me some help with this?
Looks like my project wanted MainFrameService instead of MainFrameData.
I started to delete this post, but... who knows? Perhaps someone else can get some use out of it.

Method not allowed 405 when using IIS

I have the following WCF :
[OperationContract]
IList<OperationRoomDto> GetOperationRooms();
and I have a website that uses this WCF, when I use Visual studio (Asp.Net development server) it works fine, but when I deploy the WCF to IIS I get this exception:
The remote server returned an error: (405) Method Not Allowed.
I made a simple website to test this WCF (on IIS) and It worked.
this is a part of the website web.config file:
<endpoint address="http://server/WcfService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMessageService"
contract="MyProject.Web.Wcf.IMessageService" name="BasicHttpBinding_IMessageService">
</endpoint>
and this part of the web service config file:
<system.serviceModel>
<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" />
I tried to debug the w3wp.exe service to get any hidden exception,I put a break point at the web service methods, but the debugger didn't even reach there, and the exception happened before reaching to the web service class.
I figured out the problem, it was because the Url of the wcf is not correct, it misses the service file name
<endpoint address="http://server/WcfService"
it should become :
<endpoint address="http://server/WcfService/Service.svc"

Resources