wcf web service identity servicePrincipalName explanation required - wcf

I have a web service that uses windows integrated authentication, and it works. But only after much trial and error it only finally worked with my config file endpoint section having an identity as follows:
<identity>
<servicePrincipalName value="host/servername" />
</identity>
Where 'servername' is the name of the IIS server hosting the webservice.
If I missed it out, IIS refused it (did not even get to the end point) with 'authentication error'.
However, when I recently needed to run a program on the same server as the web service this then failed with the same error and it worked only if I completely removed the identity or changed it to 'host/localhost'.
Can somebody explain why this is because I really don't understand what the servicePrincipalName/identity is really doing other than just working.
thanks.

The name of the user you wish the service to use (execute under) are placed as value for ServicePrincipalName.
You can have much simpler reference here.

Related

How to add WCF service on IIS Express?

I have the wcf service package, waiting to be put in IIS. Everything goes fine when I create a virtual directory on the default website and etc. But when I try to access the path in Chrome I get an error:
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
When I comment this section:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
I can access the directory but not the service. Any idea?
I tried a little more and figured out what I was doing wrong. I can't create an virtual path under the Default Website. I had to create my own site, which appoint to the folder where my WCF files are storage. Something like this:
appcmd add site /name:WcfService1 /id:2 /physicalPath:C:\WcfService1 /bindings:http/*:8080
This way the virtual directory will be marked as an applicattion and everything will work just fine.

WCF IIS svcutil error

I have wcf iis hosted service.
I've created standard(from vs template) wcf service and its client. At client I add ServiceReference to my wcf service. All is good. No errors, web-form for this server works too. Next step I publish my wcf service to Win2003 IIS6.0.
I successfully go to http://server:1234/Service1.svc, see web-form, can check wsdl.
But when i run: svcutil.exe http://server:1234/Service1.svc?wsdl or add service reference I've got errors:
Error: Cannot obtain Metadata from http://server:1234/Service1.svc?wsdl
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess. For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error URI: http://server:1234/Service1.svc?wsdl
Metadata contains a reference that cannot be resolved:
'http://server:1234/Service1.svc?wsdl'.
The remote server returned an unexpected response: (417) Expectation failed.
The remote server returned an error: (417) Expectation failed.
At my service config I have:
endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
serviceMetadata httpGetEnabled="true"/>
I can't understand problems.
Can you help me. Thanks a lot
Edit:
This answer was posted and isn't specifically useful to this question (any more) as it was based around a typo in the original question. That being said I still feel the information is useful here for people with similar problems that are likely to find this question in a search for their answer. If someone with the authority to remove answers feels that this needs removed - please feel free to remove it.
Original answer:
I'm not sure if this is helpful or not - I'm having a similar problem. Please notice that while you are accessing http://server:1234/Service1.svc ... further down in the error message it mentions that MEX endpoint is http://aurit-server:1234/Service1.svc... then, depending on how you have your bindings setup, it may be that aurit-server is not a valid endpoint for your service MEX... but server is or vice versa.
I know this isn't the full answer for you, I'm just pointing out something that I overlooked while troubleshooting my similar problem - hope it helps. I.e. aurit-server and server may not be interchangeable... they were not interchangeable in my case.
Edit:
Btw since posting this I've recieved an answer to a similar question that I posted. I strongly suggest you check it out incase it fixes your issue. Summary: It links to a blog post that details how to fix the issue I mentioned in my original 'suggestion' to you. If it helps you please make sure you vote Chesso up! (Chesso's answer to me, Blog post referenced in Chesso's answer).
I had this problem ("The remote server returned an unexpected response: (417) Expectation failed") when trying to add a service reference to a WCF service I'd deployed on another server. Turned out to be internet properties in this case.
Go to control panel -> internet properties, "Connections" tab.
Click the "LAN settings" button.
Uncheck "Automatically detect settings" and "Use automatic configuration script".
Click OK, apply / OK.
After that, I could add the service ref just fine. Worth a try if you have this problem.

WCF Protocol Exception

We are getting some weird behavior from a service we have deployed on a remote system which we are using to access and post data to.
Retrieving information from the service doesn't seem to be an issue. However, whenever we try to execute insert methods on the service we get an System.ServiceModel.ProtocolException. The weird thing is, it will successfully execute approximate 40 records before faulting.
The client is communicating over SSL and TransportWithMessageSecurity is enabled on the wsHttpBinding.
The error message is being generated at the "Set up Secure Session activity":
System.ServiceModel.ProtocolException,
System.ServiceModel, Version=3.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089
The content type text/html of the
response message does not match the
content type of the binding
(application/soap+xml; charset=utf-8).
If using a custom encoder, be sure
that the IsContentTypeSupported method
is implemented properly.
We have tried a number of tests all of which consistently fault as soon as we reach a particular number of inserts.
Any suggestions would be appreciated.
I wonder if the trace viewer might shed some light here? No idea what the problem is, I'm afraid...
If a piece of code sends you HTML, then you should probably read it to see what it says.
You probably have reached the configured message size and the WCF infrastructure is truncating the SOAP message, making the serializer (Contract or XML Serializer) to not be able to deserialize the message.
Try increasing the WCF request size see < readerQuotas >
ASP.NET might not be configured properly for .NET 4.0
navigate where .NET 4.0 is installed and try running the following command to reinstall it:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis.exe -iru
This could help somebody. My problem was: I have a web site consuming a WCF service.
After deploying the web site, I forgot to deploy the WCF service, too.
After deploying the WCF service, all worked fine.
I ran into the same problem. Finally, I got a solution by adding some code in the web.config file.
I added these under the <basicHttpBinding> tag:
<binding name="xyz">
<security mode= "Transport" />
</binding>

WCF Errors using WCFTestClient to test a simple WCF Web Service

When I try to test the AutoLotWCFService using "wcftestclient", I get the following error. What am I doing wrong? Any insight will help. This is a simple Web Service that has wshttpbinding with interface contract and the implementation in the service. Here is the long error message: The Web.Config file has 2 endpoints - one for Web Service itself and other for metaDataExchange. Its all pretty much default stuff. I can include the code if needed - it seems I cannot attach files here.
Error: Cannot obtain Metadata from http://localhost/AutoLotWCFService/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/AutoLotWCFService/Service.svc
Metadata contains a reference that cannot be resolved: 'http://localhost/AutoLotWCFService/Service.svc'.
The remote server returned an unexpected response: (405) Method not allowed.
The remote server returned an error: (405) Method Not Allowed.
HTTP GET Error URI: http://localhost/AutoLotWCFService/Service.svc
The document at the url http://localhost/AutoLotWCFService/Service.svc was not recognized as a known document type.The error message from each known type may help you fix the problem:
- Report from 'DISCO Document' is 'Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.'.
- Report from 'WSDL Document' is 'There is an error in XML document (1, 2).' -Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.
- Report from 'XML Schema' is 'Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.'.
I recently had this problem whilst trying to host WCF on my Windows Vista Laptop under IIS7.
I first recieved the following error : "HTTP Error 404.3 - Not Found" and one of the resolutions suggested was to "Ensure that the expected handler for the current page is mapped."
So I added a handler for the .svc file manually and defined it as a DiscoveryRequestHandler, thinking that this might help. This caused the problem you described above.
The actual resolution was to delete the handler I had added, and to run the following commands:
CD c:\windows\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\
ServiceModelReg -i
This resolved my issue and the service is working fine. I hope this might help shed some light on your problem. I can't be certain but this is probably because of the order in which I've installed the various packages on my dev laptop.
If installing compenonts doesnt work try a repair, this uninstalls and then installs.
"%WINDIR%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r
you need to make sure that the service behaviour configuration enables has a metadata tag with httpGetEnabled="true"
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true">
&lt/behavior>
</serviceBehaviors>
In addition, make sure your service references that behavior.
<service name="blah" behaviorConfiguration="serviceBehavior">
Thanks; believe it or not the problem of at least loading the service through wcftestclient was solved when I re-registered the ASPNET in IIS with aspnet-regiis.
The next problem is to be able to invoke the methods exposed by the service through wcftestclient. What are the security issues that I have to deal with? I had to enable Anonymous login with windows auth. and still the invoke generated exceptions that pointed to something related to access violation. On searching some things point to installing certificates to be able to invoke.. Please enlighten if possible.
Try checking if service(name) in the Service Markup (right click on servicename.svc) matches the service(name) in your web.config file.
Cheers!

Why cant my Silverlight application load data from sql on live site using WCF?

My silverlight application loads data fromt he SQL fine when I build locally but when I upload it to the live site it will just wait for data to be loaded but show no errors. It worked up until yesterday where I fear I may have changed a setting somewhere and now I cant access the data it seems?
UPDATE 1: it seems to be a problem with the service references. Everytime I update them, it will clear the ServiceReferences.ClientConfig file and then the program wont build.
UPDATE 2: I have tried cleaning and building but still the same problem.
UPDATE 3: Found an error when trying to access the service reference on the live site:
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
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.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
It sounds like your application is waiting for something, does it time out after 30 seconds? If so, check your SQL connection string.
If there is another tier between Silverlight and SQL (such as a web service), then set up a connection test to make sure that Silverlight is actually reaching SQL...
Did you accidentally replace your live web.config file? If so, try restoring the old web.config as it may have a setting that's not compatable with your server.
Re: Update 1:
Is there an error? If so please paste it. Also please paste the config file in question on pastebin and link to it from here.
Re: Update 3:
The error "This collection already contains an address with scheme http." is caused by not telling a WCF service explicitly what address you wish to bind to when there are many to chosoe from. In this case it looks like IIS is using multiple URLs, for example, consider these fictional addresses:
www.mysite.com
mysite.com
... so the WCF service has no idea which to use unless you tell it.
The solution, to this is to explictly define what URL to use with the following config lines in the web.config (within the system.serviceModel node) of your WCF service.
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://www.mysite.com/SomeDirectory/MyService" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
Important:
You should update your question title to indicate that WCF is involved in the solution you have created.