Deploy WCF Web Service in IIS 7 - Getting Error - asp.net

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

Related

Unable to Resolve Host Name of SOAP Service

I've added a service reference to a third party API that I have no control over.
The endpoint looks like this (URL masked) and the service is available from this address as I can call it using SOAPUI:
<endpoint address="https://some-api.domain.com/service-name/do-something"
binding="basicHttpBinding" bindingConfiguration="FindPolicyPortSoap11"
contract="FindPolicy.FindPolicyPort" name="FindPolicyPortSoap11" />
When calling the service, I get the error The remote name could not be resolved: 'some-api.domain.com which is technically correct as some-api.domain.com will produce a 404 whereas some-api.domain.com/service-name/do-something works as expected.
What can I do to get this working?
Have you tried setting the defaultproxy to true in system.net tag?
Accordig to MSDN
If the defaultProxy element is empty, the proxy settings from Internet
Explorer will be used. This behavior is different from version 1.1 of
the .NET Framework.
<defaultProxy
enabled="true|false"
useDefaultCredentials="true|false">
<bypasslist> … </bypasslist>
<proxy> … </proxy>
<module> … </module>
</defaultProxy>
https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/defaultproxy-element-network-settings
This error related to resolving some-api.domain.com to specific ip address
I would try using nslookup or
http://www.kloth.net/services/nslookup.php
Another option is to add this domain to your hosts file just to test it

WCF client methods called from ASP.NET app return 404 Not Found

I have a library that contains a Service Reference generated proxy to a remote ASMX web service. When I try to call methods on that proxy from an ASP.NET application, I get the following error:
System.ServiceModel.EndpointNotFoundException: There was no endpoint
listening at https://domain.com/path/to/the.asmx that could accept the
message. This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details. --->
System.Net.WebException: The remote server returned an error: (404)
Not Found.
However, if I call the same methods from a simple console app dropped into the bin folder (and therefore referencing the exact same libraries), it works. I have the same, simple configuration in web.config and the console app's app.config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="ServicesSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://domain.com/path/to/the.asmx"
binding="customBinding" bindingConfiguration="ServicesSoap12"
contract="TheContract" name="ServicesSoap12" />
</client>
</system.serviceModel>
Tracing revealed no further useful information. The ASMX endpoint is definitely available. What could cause this behavior, and what other troubleshooting steps can I take?
This turned out to be a parameter issue. My production code was passing null for an optional string parameter, but my test code was passing a guid. The parameter is optional in the contract, so I don't understand why it triggered a 404, but I'm able to consistently reproduce the problem by passing null.
The contract parameter is defined as follows:
<s:element minOccurs="0" maxOccurs="1" name="userdef1" type="s:string"/>
The 404 error threw me off from the beginning. It's a reminder to always write your test code exactly like the code that doesn't work.

Ajax-Enabled WCF Service return error 500 when hosted on IIS

I'm trying to set up an Ajax-Enabled WCF Service with my Web Application. I can use it just fine with visual studio, however when I publish the website and host it on IIS, the service doesn't seem to be managed properly.
For instance :
When Hosting the web site through Visual Studio (with cassini I assume), I get a Javascript file generated on my localhost localhost:62006/WebServices/SaphirExternService.svc/jsdebug which allows me to call the method of the webservice from the javascript.
However on the production environnement, when I should be getting /WebServices/SaphirExternService.svc/js there is a server 500 error. Actually I cant even browse to url/WebServices/SaphirExternService.svc (same 500).
The error is as follow (translated approximately) :
could not load the type 'System.ServiceModel.Activation.HttpHandler' from the assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
MyService.svc contains :
<%# ServiceHost Language="C#"
Debug="true" Service="WebApplication.WebServices.SaphirExternService"
Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"
CodeBehind="SaphirExternService.svc.cs" %>
The service is declared as follow in the aspx :
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
<Services>
<asp:ServiceReference Path="~/WebServices/SaphirExternService.svc" />
</Services>
</asp:ScriptManager>
and called as follow in the javascript :
var service = new WebServices.SaphirExternService();
service.DoWork("test", DoWorkSuccess, null, null);
Finally the Web.config :
<services>
<service name="WebApplication.WebServices.SaphirExternService">
<endpoint address="" behaviorConfiguration="WebApplication.WebServices.SaphirExternServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="WebApplication.WebServices.SaphirExternService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WebApplication.WebServices.SaphirExternServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
This works fine on visual studio itself however this no longer work when published and hosted on IIS (since the /js file is not generated, SaphirExternService is not defined). I've tried using several endpoint configuration (like the bindingConfiguration attribute) to no avail. What am I missing ?
Found the solution to my issue in case someone needs it for future reference. The svc file were not mapped properly in IIS. I removed all *.svc related configuration in the Handler Mappings. Then in two steps :
Added a new Mime Type :
Extension: .svc
MIME type: application/octet-stream
In Handler Mapping > Added a new managed code Handler:
Request path: *.svc
Type: System.ServiceModel.Activation.HttpHandler
Name: svc-Integrated

Permissions issue using MSBuild extension pack and IIS7 tasks

im trying to use the iis7 web task in the extension pack. I cant successful use the task(with my god level admin access), but my issue is that i cant use it with the user that must run it (service user).
<Target Name="CheckForSite">
<Message Text="Site: $(Site)" />
<Message Text="Application: $(Application)" />
<Message Text="Server: $(Server)" />
<Message Text="PhysicalPath: $(PhysicalPath)"/>
<!-- Check if the site exists -->
<MSBuild.ExtensionPack.Web.Iis7Website TaskAction="CheckExists"
Name="$(Site)"
MachineName="$(Server)"
>
<Output TaskParameter="Exists" PropertyName="SiteExists"/>
</MSBuild.ExtensionPack.Web.Iis7Website>
<Message Text="Site Exists: $(SiteExists)" Condition="$(SiteExists)"/>
<Message Text="Site does not exist: $(SiteExists)" Condition="(!$(SiteExists))"/>
I get the error:
error : UnauthorizedAccessException: Retrieving the COM class factory for remote component with CLSID {2B72133B-3F5B-4602-8952-803546CE3344} from machine failed due to the following error: 80070005
It is access denied exception. Try to add Username="username" UserPassword="password" properties into the MSBuild.ExtensionPack.Web.Iis7Website task. User should be admin on the target machine.
In my case I had a problem with domain communication. My server is in the different domain as my user's domain. It was fixed by our infrastructure team. I found this issue in the event log. Check event logs first for any related issues.

Asp.net not authenticating against wcf service on server 2008

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

Resources