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.
Related
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 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.
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"
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
}
I am having a tough time deploying a web site to IIS 7 on Windows Server 2008.
The site works fine until it tries to make calls to a WCF service hosted on the same host.
Everything works great for the service from my workstation when the web is ran in Visual Studio 20008
using the exact same web config etc. As soon as I deploye the web in a virtual directory on the server
Bam. Authentication errors. It also works as is when both are deployed on a Windows 2003 Server. What
is different about Server 2008 that is causing this? HELP! Please.
In case it is important, all of the service operations require Active Directory group membership for the
ASP.net page's authenticated user and are adorned as:
[PrincipalPermission(SecurityAction.Demand, Role = "SOAMemberShipService")]
I get the following error from the web site:
The request for security token could not be satisfied because authentication failed.
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.ServiceModel.FaultException: The request for security token could not be satisfied because authentication failed.
Source Error:
Line 919:
Line 920: public HSMembersService.MemberSearchResult SearchMembers(HSMembersService.MemberSearch MemberInfoToSearch) {
Line 921: return base.Channel.SearchMembers(MemberInfoToSearch);
Line 922: }
Line 923: }
Source File: c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\csrweb\a4d18657\a6d0910d\App_WebReferences.jgx1svpr.0.cs Line: 921
Stack Trace:
[FaultException: The request for security token could not be satisfied because authentication failed.]
System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target) +6375432
System.ServiceModel.Security.IssuanceTokenProviderBase`1.ThrowIfFault(Message message, EndpointAddress target) +25
System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState) +173
[SecurityNegotiationException: The caller was not authenticated by the service.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4596611
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1713
HSMembersService.IHSMembersService.SearchMembers(MemberSearch MemberInfoToSearch) +0
HSMembersService.HSMembersServiceClient.SearchMembers(MemberSearch MemberInfoToSearch) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\csrweb\a4d18657\a6d0910d\App_WebReferences.jgx1svpr.0.cs:921
_default.btnSearch_Click(Object sender, EventArgs e) in e:\CSRWeb\default.aspx.cs:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +131
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +39
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3215
ASP.net web site's web.config (relevant Service portion):
Services web.config:
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="HSMembersService.IHSMembersService" bindingConfiguration="wsHttpBindingConfig">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<!--<identity>
<dns value="localhost"/>
</identity>-->
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBindingConfig" >
<security mode="Message">
<message clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="HSMembersService.HSMembersServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<serviceAuthorization principalPermissionMode="UseWindowsGroups" />
<!-- 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" /><!-- Change this before deployment -->
</behavior>
</serviceBehaviors>
</behaviors>
Okay, no answers here nor on the MSDN subscription groups.
So, I tried everything. And I mean everything. After what seemed like several days but in reality was probably only 20 hours, it works!
All I did was move the physical path the services files i.e. .dll, .svc etc. to a directory off of my c:root versus the wwwroot and it worked. I had to update my virtual directory to point to it of course.
Why did this location cause a problem? Does IIS7.0/Windows server 2008 change something that doesn't allow services to be deployed from a physical location of wwwroot? I'll probably never find out because I will never try to deploy another service from there.
I triple-checked all account/directory permissions and the ones in the new physical path are identical to the ones in the old physical path so no good there.
If anyone finds out why or knows why. Please let me/us know.
Thanks,
Eddie