Following is my WCF configuration. I published it in IIS and trying to connect to it from a Windows forms client.
<system.serviceModel>
<client />
<bindings>
<wsHttpBinding>
<binding name="BindingConfiguration">
<security>
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Service" behaviorConfiguration="BehaviorConfiguration">
<endpoint address="" binding="wsHttpBinding" name="wsBinding" contract="WCFHttps.IService1" bindingConfiguration="BindingConfiguration"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name= "BehaviorConfiguration">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Windows"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
It throws an error while trying to add service reference in the test client.
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: '****/Service1.svc?wsdl'.
Content Type application/soap+xml; charset=utf-8 was not supported by service ****/Service1.svc?wsdl. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
I have also granted read/write permissions for IIS_USRS over C:\Windows\Temp folder but still the problem persists. Can anyone suggest what's wrong here.
Thanks.
cause:
Cause of this error is simple when you try to refer the WCF service IIS tried to access C:\Windows\Temp folder. If ASP.NET or IIS_IUSER(based on the windows version) account doesn’t have access to this folder you will see this error.
Solution:
Add ASP.NET or IIS_USER account to this folder or give admin rights to the user account you are running your application.
Configuring Tracing
http://msdn.microsoft.com/en-us/library/ms733025.aspx
In my case wrong namespace was specified in web.config file. It has to be same as namespace of your .svc file:
<service name="NAMESPACE.SvcFileName">
<endpoint contract="NAMESPACE.IContractName" />
</service>
Example:
<service name="MyNameSpace.FileService">
<endpoint contract="MyNameSpace.IFileService" />
</service>
(Unrelevant tags ommited in these samples)
Related
I am trying to add transport security layer to my WCF service. But after following all the instructions i still get error "Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http]."
Already did all needed configurations in IIS Manager and add need code in web.config but i still have a feeling i am missing something
web.config:
<system.serviceModel>
<services>
<service name="MyNameSpace.MyService" behaviorConfiguration="secureBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyNameSpace.IMyService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="secureBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
There is no problem with your present configuration, configure an https endpoint and it uses Transport security mode. One more thing we need to do is configuring an https binding address in IIS binding module. Like below.
It locates in the IIS site binding module.
Then we could use the above https service address to access it.
https://IP:4431/Service1.svc (service base address)
Feel free to let me know if the problem still exists.
I'm trying to add a service reference to my wcf app in visual studio.
I can do it for various bindings such as net.pipe and basichttp...
but to net.msmq binding, I get error
Here is the relevant part of my web.config:
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="netMsmqBinding" exactlyOnce="false">
<security mode="None"></security>
</binding>
</netMsmqBinding>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WCF_ServiceSample.WCF_ServiceBehavior" />
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata />
<serviceDebug />
<serviceDiscovery />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="serviceBehavior" name="WCF_ServiceSample.WCF_Service">
<host>
<baseAddresses>
<add baseAddress="http://localhost:4000/Services/" />
<add baseAddress="net.msmq://localhost/Services/" />
</baseAddresses>
</host>
<endpoint address="mex" behaviorConfiguration="WCF_ServiceSample.WCF_ServiceBehavior"
binding="mexHttpBinding" bindingConfiguration="" name="mex_http"
contract="IMetadataExchange" />
<endpoint address="AdventureWorksServiceHttp" binding="basicHttpBinding" bindingConfiguration=""
name="basicHttpEndpt" contract="WCF_ServiceSample.WCF_Service" />
<endpoint address="AdventureWorksServiceNetMsmq"
binding="netMsmqBinding" bindingConfiguration="netMsmqBinding"
contract="WCF_ServiceSample.WCF_Service" />
</service>
</services>
</system.serviceModel>
Here is the error I get when I run my service via the wcf client:
Error: Cannot obtain Metadata from
http://localhost:9011/WCF_Service.svc If this is a Windows (R)
Communication Foundation service to which you have access, please
check that you have enabled metadata publishing at the specified
address. For help enabling metadata publishing, please refer to the
MSDN documentation at
http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange
Error URI: http://localhost:9011/WCF_Service.svc Metadata contains a
reference that cannot be resolved:
'http://localhost:9011/WCF_Service.svc'. The server did not provide a
meaningful reply; this might be caused by a contract mismatch, a
premature session shutdown or an internal server error.HTTP GET Error
URI: http://localhost:9011/WCF_Service.svc There was an error
downloading 'http://localhost:9011/WCF_Service.svc'. The request
failed with the error message:-- Server Error in '/' Application.
Could not find a base address that matches scheme net.msmq for the
endpoint with binding NetMsmqBinding. Registered base address schemes
are [http]. Description: An unhandled exception occurred during the
execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
here is the error I get when I go to add service reference ->
net.msmq://localhost/WCF_Service.svc
then I press "Go"
The URI prefix is not recognized. The MetadataExchangeClient instance
could not be initialized because no Binding is available for scheme
'net.msmq'. You can supply a Binding in the constructor, or specify a
configurationName. Parameter name: scheme If the service is defined in
the current solution, try building the solution and adding the service
reference again.
add mex bindings as that will allow you to add proxy reference, then you can use the net.msmq bindings to do the operation.
What is "mexHttpBinding"?
https://msdn.microsoft.com/en-us/library/aa967390(v=vs.110).aspx
I am learning WCF and i need to create a simple WCF service with a https binding. Need to have it as secure as possible.
So far i succeeded in creating a self-hosting wcf by using this guide:
Codeproject enable certificates on WCF
Managed to consume it, everything looks great. But the real problems appear when i try to host this in IIS 8. Local IIS, not IIS express.
I created a new wcf application in visual studio 2012, and in project's properties -> Web -> servers, i selected Local IIS, project URL: https://localhost/AdminService , Create virtual directory.
This added an application under Default Web Site in IIS Manager. The thing is, using the same web-config as my self-hosted app, roughly modified, did not work.
After altering it a bit, i got to this:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate"/>
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WCFServiceCertificate.SecureServiceBehavior"
name="AdminService.AdminService">
<!--<host>
<baseAddresses>
<add baseAddress="https://localhost:1234/AdminService" />
</baseAddresses>
</host>-->
<endpoint address="https://localhost/AdminService" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding"
contract="AdminServiceContract.IAdminService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFServiceCertificate.SecureServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust" />
</clientCertificate>
<serviceCertificate findValue="CertAdminService" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
That CertAdminService certificate was not created with makecert, like i did in the self-hosted wcf, but i created it with iis manager's "create self-signed certificate".
Then, on Default Web Site -> bindings, i added a new binding, https, and selected this certificate.
The problem is, even if i choose browse (*:443) on default web site, or my application, i get the following error:
Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
Error code: ERR_SSL_PROTOCOL_ERROR
I have no idea what am i doing wrong. Also, having the mexHttpsBinding enabled, if i try to add service reference to another project, i can discover the service, but i get the following error:
"There was an error downloading 'https://localhost/AdminService/AdminService.svc/_vti_bin/ListData.svc/$metadata'.
The underlying connection was closed: An unexpected error occurred on a send.
The handshake failed due to an unexpected packet format.
Metadata contains a reference that cannot be resolved: 'https://localhost/AdminService/AdminService.svc'.
An error occurred while making the HTTP request to https://localhost/AdminService/AdminService.svc.
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.
The underlying connection was closed: An unexpected error occurred on a send.
The handshake failed due to an unexpected packet format.
If the service is defined in the current solution, try building the solution and adding the service reference again."
Any help will be much appreciated, i kind of ran out of ideas. According to other posts on stackoverflow that i've read, this should've work. Maybe i'm doing something wrong and i don't know what.
Thank you, and sorry for the long post.
Edit:
Here is the consuming client's web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IAdminService">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate" />
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/AdminService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAdminService"
contract="AdminServiceContract.IAdminService" name="WSHttpBinding_IAdminService" behaviorConfiguration="CustomBehavior">
<identity>
<dns value="WCfServer" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="CustomBehavior">
<clientCredentials>
<clientCertificate findValue="CertAdminService" x509FindType="FindBySubjectName"
storeLocation="LocalMachine" storeName="My" />
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I have an IIS hosted WCF webservice. It started with two consumers.
1) A WinForm test harness in the same solution to test the WCF contracts in the IDE.
2) An Asp.Net Web App that is consuming the published version.
All was working out of the box so to speak.
Then along came the 3rd consumer, an Android app. To get this consuming correctly had to decorate the WCF contracts with JSON WebGets and Webinvokes and alter the WCF Web.config to suit.
Now the original two consumers no longer work. So I need to alter Web.config and / or App.configs to get a configuration where all three work.
Focusing on the IDE first. I have the following service model section for the WCF service Web.Config.
<system.serviceModel>
<client>
<endpoint binding="webHttpBinding" bindingConfiguration="JsonBinding"
contract="CouponParkingWCF.ICouponService" name="Json"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="http://localhost:8707/CouponParking.svc"
binding="basicHttpBinding" contract="CouponParkingWCF.ICouponService"
name="BasicHttpBinding_ICouponService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
<webHttpBinding>
<binding name="JsonBinding" />
</webHttpBinding>
</bindings>
<services>
<service name="CouponParkingWCF.CouponService">
<endpoint behaviorConfiguration="JsonBehavior" binding="webHttpBinding"
bindingConfiguration="" name="jsonEndPoint"
contract="CouponParkingWCF.ICouponService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="false" />
</system.serviceModel>
The WinForm Test harness App.config has:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttp" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8707/CouponParking.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttp"
contract="CouponParking.ICouponService"
name="BasicHttpBinding_ICouponService" />
</client>
</system.serviceModel>
I am not experienced at configuring endpoints and the above has been based on examples and guesswork.
When I run the Test Harness the wcf Client instantiates but a call on a contract fails with :
There was no endpoint listening at http://localhost:8707/CouponParking.svc
that could accept the message. This is often caused by an incorrect address
or SOAP action. See InnerException, if present, for more details."
The inner exception is :
{"The remote server returned an error: (404) Not Found."}
[System.Net.WebException]: {"The remote server returned an error: (404) Not Found."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
HResult: -2146233079
InnerException: null
Message: "The remote server returned an error: (404) Not Found."
Source: "System"
StackTrace: " at System.Net.HttpWebRequest.GetResponse()\r\n at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)"
TargetSite: {System.Net.WebResponse GetResponse()}
I would appreciate some guidance on what I have got wrong.
Thanks
At a glance, it appears that you've mixed up client endpoints with service endpoints in your service's config file. There's no reason for client endpoints to appear in the service's config file, unless that service is itself calling another service.
Your WinForm's config file is defining a client with basicHttpBinding, but you do not expose a service endpoint with BasicHttpBinding, which is most likely the reason for the error you're getting.
I would try deleting the client endpoints in your service's config file, and add them to the <services> section, like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
<webHttpBinding>
<binding name="JsonBinding" />
</webHttpBinding>
</bindings>
<services>
<service name="CouponParkingWCF.CouponService">
<endpoint address="SOAP"
binding="basicHttpBinding"
contract="CouponParkingWCF.ICouponService"
name="BasicHttpBinding_ICouponService" />
<endpoint address="JSON"
binding="webHttpBinding" bindingConfiguration="JsonBinding"
contract="CouponParkingWCF.ICouponService" name="Json"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
</service>
</services>
Remember the ABC's of WCF: A = Address, B = Binding and C = Contract - those three items define a service.
Since you added a client that needed a different binding then your test harness or your ASP.NET application, you need to expose a second endpoint with that binding.
EDITED
As #marc_s pointed out, you'll need two distinct relative addresses. I've updated the config file to reflect that.
I've not had an occasion to use multiple endpoints myself, but I believe you'd use them this way, with the base address being provided by the location of the *.svc file:
http://localhost:8707/CouponParking.svc/SOAP
http://localhost:8707/CouponParking.svc/JSON
With the first being for the BasicHttpBinding and the second being for the WebHttpBinding.
You basically just need two separate endpoints to provide both the basicHttpBinding (a SOAP binding) and the webHttpBinding for your Android client (a REST binding).
The "base" address of your service is defined by your IIS virtual directory and where the *.svc file lives (http://localhost:8707/CouponParking.svc) - so both services will be reachable at this "base" address plus any relative address defined
So you need to configure this something like this:
<services>
<service name="CouponParkingWCF.CouponService">
<!-- define the basicHttp (SOAP) endpoint at the base address -->
<endpoint name="SoapEndpoint"
address=""
binding="basicHttpBinding"
contract="CouponParkingWCF.ICouponService" />
<!-- define the REST endpoint at (base)+"/rest" -->
<endpoint name="RestEndpoint"
address="rest"
behaviorConfiguration="JsonBehavior"
binding="webHttpBinding"
contract="CouponParkingWCF.ICouponService" />
</service>
</services>
With this setup, you should be able to call your service using the basicHttpBinding (SOAP) at
http://yourServer:8707/CouponParking.svc
and you should be able to access the REST-based, JSON-enabled endpoint at
http://yourServer:8707/CouponParking.svc/rest
Both server-side endpoints will be handled by the same service code - it's just the endpoint (and the protocols that endpoints understands) that are different
I created simple wcf service with default functionality and hosted in IIS7. Its working fine and rendering data to the client. But when I try to click on wsdl link in the service its showing "Page cannot be displayed".Let me know what will be the problem
.
When I try to click the link below (http://win-nsms.smsserver.com/VirtualFolder/MyService.svc?wsdl), WSDL file is not getting displayed in the browser. Instead I am getting "The page cannot be displayed" error in the page
Now If I change the "win-nsms.smsserver.com" to "localhost" in the URL, WSDL file is getting displayed.
Yes I added behaviour configuration in my config as follows
<system.serviceModel>
<services>
<service name="WcfServiceSample.Service1" behaviorConfiguration="WcfServiceSample.Service1Behavior">
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceSample.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://win-nsms.smsserver.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceSample.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
Have you allowed retrieval of service meta data?
In the behaviours section of your config file, add a new behaviour like this:
<behaviors>
<serviceBehaviors>
<behavior name="HttpGetMetadata">
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
Then tell your service to use this behaviour:
<system.serviceModel>
<services>
<service name="MyService"
behaviorConfiguration="HttpGetMetadata">
....
This is telling your service to allow the service metadata (the WSDL) to be retrieved via http. To confirm you can browse to the appropriate URL.
Is "mymachinename.domainname.com" added as a hostmask in IIS for the site?
You may need to setup the base address for the service.
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://mymachinename.domainname.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
I had a similar problem where the service was working 100% for domain.com but not www.domain.com. I had to setup the latter as a redirect to the former and set the base address to the former.
HTH!
Did you enable WDS exposure? Standard settings dont show the WDSL.