Having a behaviour for a endpoint, I specified a serviceCertificate to be used.
Everything works fine, but every year we get a new certificate on our servers while the old ones are being left undeleted.
This results in 2 valid certificates (overlapping few days in validity period), both with the same name. When having 2 certificates with the same name, using the service throws an error:
The exception message is: Found multiple X.509 certificates using the following search criteria: StoreName 'My', StoreLocation 'LocalMachine', FindType 'FindBySubjectName', FindValue 'CertName'. Provide a more specific find value
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehaviour">
<serviceCredentials>
<serviceCertificate findValue="CertName" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
I know how to solve this problem for now by deleting the old certificate, but I found no way to solve this for long term, i.e. taking always the first valid certificate.
Is there any way to specify to take one certificate, regardless of the number of available ones that match? I don't want to modify our config files everytime we get a certifcate renewed.
Related
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.
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
I'm trying to add a service reference in VS 2010 to a WCF Web Service I have on a Server 2008/IIS7 server. I put the service into an existing/working ASP.NET site. When I type in the url of the service, it comes up with the standard service screen, but when I try to add the reference to a new website project I'm developing, I get the following error.
The document at the url https://www.nameofsite.net/service.svc?wsdl was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'https://www.nameofsite.net/service.svc?wsdl' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'DISCO Document' is 'Discovery document at the URL https://www.nameofsite.net/Service.svc?disco could not be found.'.
- The document format is not recognized.
- Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
Metadata contains a reference that cannot be resolved: 'https://www.nameofsite.net/service.svc?wsdl'.
There was no endpoint listening at https://www.nameofsite.net/service.svc?wsdl that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.
I tried adding the mime type svc to IIS and that didn't work. I see that there's a lot of talk about soap 1.1 not communicating with soap 1.2 but I'm too new to this to even follow the instructions I've seen. Please help. Thanks.
Is the service publishing its metadata? Check the httpsGetEnabled flag in the web.config file for the service:
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpsGetEnabled="true"
httpsGetUrl="https://myComputerName/myEndpoint" />
</behavior>
</serviceBehaviors>
</behaviors>
For more info on these tags: ServiceMetaData
You may also need this endpoint configured in your web.config for the service:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
Some more background:
Web.Config
WSDL vs MEX
I'm trying to solve my problem when I send class Product (including a binary[] Picture). If I send a Product containing a picture of around 14KB it works, but if I increase the size to 17KB I get the error message:
"The remote server returned an unexpected response: (400) Bad Request.
Because it works with smaller pictures I think it is something wrong with my configurations.
Client (winform) app.config:
http://www.copypastecode.com/157335/
Server web.config:
http://www.copypastecode.com/157339/
I've tried to increased every value (maxBufferSize, maxReceivedMessageSize..) to MAX without any progress?
If you are sending array you should check
maxArrayLength
setting as you most probably hit this limit. What is the length of your array when with 17kb file?
But in general, the best way to upload \ download files are stream upload \ download endpoints
You might consider adding the DataContractSerializer element in your serviceBehaviour element to define the maxItemsInObjectGraph as shown below
<serviceBehaviors>
<behavior name="">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
Also try to add Tracing on your service and see the trace log for the exact reason on why the request is failing.
If your total request length is exceeding 4MB then make sure you have the below:
<system.web>
<httpRuntime maxRequestLength="2147483647"/>
</system.web>
I have a wcf service that randomly begins to fail, when requesting the autogenerated javascript that wcf supports in making. But I have no luck tracking down why,the js thing is part of the wcf featureset.So I dont know how it can suddenly begin to fail and be unable to work until IIS is recycled.
The http log gives me:
2010-06-10 09:11:49 W3SVC2095255988 myip GET /path/myservice.svc/js _=1276161113900 80 - ip browser 500 0 0
So its an error 500, and that is about the only thing I can figure out. The event log contains no information.
Requests to /path/myservice.svc works just fine. After recycling IIS it works again, and some days later it begins to fail until I recycle IIS.
<service
name="path.myservice"
behaviorConfiguration="b">
<endpoint
address=""
behaviorConfiguration="eb"
binding="webHttpBinding"
contract="path.Imyservice" />
</service>
...
<endpointBehaviors>
<behavior name="eb">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="b">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
I dont see any problems in the web.config settings either.
Any clues how I can track down what the problem is?
Edit:
Just to make it clear - It is the generation of javascript that fails, my code is never invoked. Calls to the service works just fine.
I would recommend you to enable tracing in your service and look at the generated logs with Service Trace Viewer Tool. Trace only errors to keep your logs small.
It seems your WCF Service throws an Exception. You can catch this unhandled Exception in the Application_Error method in Global.asax, than write it to a log file.
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
//TODO: write to log
}