blog community
Unable to generate a WCF proxy using svcutil but retrieving the wsdl works?
Tags van Technorati: ,

The other day at a client project, we wanted to generate a proxy using svcutil as we'd done many times before.

However, the svcutil kept throwing strange error messages. Amongst them were:

  • Other mime type expected, expected application/soap+msbin1 but got application/soap+xml (HTTP error 415)
  • Could not import namespace <xyz>

As it turned out, the problem was the following: Everything seemed to work because going to the .svc URL and adding ?wsdl produced the desired output.

However, this wsdl does some schema imports, by referencing the svc URL, but this time using ?xsd=xsd0 , ?xsd=xsd1 etc. The strange thing was that these references produced errors (also when referenced by URL via Internet Explorer). This was also the reason that svcutil started throwing errors...

After some more investigation, the culprit became clear. In order to generated the xsd output, the WCF service executes some code generation and dynamically compiles this. (Discovered using the procesmon sysinternals tool). In order to be able to do that, the current Identity (in this case the AppPool Identity of our virtual directory) needs to have the "List Folder / Read Data" permission, which it does not normally have.

All these problems do not occur if you are running your website under the Network Service account, because account in fact does have these rights.

So in the end the trick is to add the additional right on the c:\windows\temp folder for your App Pool Identity to solve the problem.

Interestingly, if you look at the default rights using IIS7 and Vista, there is a default right assigned to the IIS_IUSERS group on the c:\windows\temp directory. Can you guess the additional permission :-) ? Probably MS has run into the same problem and fixed it in Vista and hopefully also in Windows Server 2008. In this case, making your App Pool Identity a member of the IIS_IUSERS group should be sufficient.

[15-2-2008: Fixed typo]


Posted 14-02-2008 0:19 by Raimondb
Filed under: ,

Comments

Matthieu wrote re: Unable to generate a WCF proxy using svcutil but retreiving the wsdl works?
on 14-02-2008 9:47

Thanks a lot for your post!!! I've tried for 4 hours to find the problem. Giving to "Everyone" 'modify' right on the 'c:\windows\temp' directory solved the issue!

Jos van Dixhoorn wrote re: Unable to generate a WCF proxy using svcutil but retreiving the wsdl works?
on 14-02-2008 10:11

"...problem and fixed it voor Vista.." What's a 'voor'?! ;)

Raimondb wrote re: Unable to generate a WCF proxy using svcutil but retreiving the wsdl works?
on 15-02-2008 23:58

Typo fixed :-)

Weston wrote re: Unable to generate a WCF proxy using svcutil but retrieving the wsdl works?
on 25-04-2008 18:55

Thank you.

Thank YOU.

THANK YOU.

THANK YOU!

Life was good. My WCF service was running fine. Until I needed to make a tiny addition to the service. And I could no longer update the web reference in the client.

Spent 5 hours at office to try to understand why. Went home and tried 3 hours to understand why. Googled, googled, tested, ran process explorer, nothing.

Until I hit this page.

Yep. I had changed the account of the app pool so that I could access another app from the service.

After given the rights to the temp dir, all works again.

I'll grab a beer now, and would gladly offer you one too. Or two.

Thanks. Saved me.

Chandra P Singh wrote re: Unable to generate a WCF proxy using svcutil but retrieving the wsdl works?
on 07-10-2008 23:51

Me too spent more than 10 hours for searching the solution for this problem. I tried same code on Vista IIS7 and getting different error and on IIS 6 on Win 2003 different. Given permission on temp folder and it got solved.

Thanks a lot.

Neil wrote re: Unable to generate a WCF proxy using svcutil but retrieving the wsdl works?
on 04-12-2008 19:16

Thanks so much for this post, you just saved me from hours of frustration!

prashant wrote re: Unable to generate a WCF proxy using svcutil but retrieving the wsdl works?
on 05-03-2009 15:40

Hi,

I am preparing  a [microsoft] service bus demo application using WCF application project, so that I can add this service ref. in my client using Add Service Ref. feature.

But I am not able to run the client, as it gives error,

"Transport security is required for this connection.The endpoint requires a secure channel to connect."

Here is my Service.config

1 <?xml version="1.0" encoding="utf-8" ?>  

2 <configuration>  

3   <system.web>  

4     <compilation debug="true" />  

5   </system.web>  

6      

7   <system.serviceModel>  

8     <bindings>  

9       <!-- Application Binding -->  

10       <netTcpRelayBinding>  

11         <binding name="default">  

12           </binding>  

13       </netTcpRelayBinding>  

14     </bindings>  

15     <services>  

16       <service behaviorConfiguration="GRSService.Service1Behavior"  

17         name="GRSService.WOService">  

18         <endpoint address="sb://servicebus.windows.net/services/<MysolutionName>/WOService"  

19                   name="RelayEndpoint"  

20                   binding="netTcpRelayBinding"  

21                   bindingConfiguration="default"  

22                   contract="GRSService.IWOService">  

23           <identity>  

24             <dns value="localhost" />  

25           </identity>  

26         </endpoint>  

27         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />  

28         <host>  

29           <baseAddresses>  

30             <add baseAddress="http://localhost/WOService" />  

31           </baseAddresses>  

32         </host>  

33       </service>  

34     </services>  

35     <behaviors>  

36       <serviceBehaviors>  

37         <behavior name="GRSService.Service1Behavior">  

38              

39           <serviceMetadata httpGetEnabled="True"  

40                            policyVersion="Policy15" httpGetUrl="http://localhost/WOService/wsdl" />  

41           <serviceDebug includeExceptionDetailInFaults="False" />  

42           </behavior>  

43       </serviceBehaviors>  

44     </behaviors>  

45   </system.serviceModel>  

46   <system.net>  

47     <defaultProxy useDefaultCredentials="true"></defaultProxy>  

48   </system.net>  

49 </configuration>  

50  

And Client.config 1 <?xml version="1.0" encoding="utf-8" ?>  

2 <configuration>  

3     <system.serviceModel>  

4         <bindings>  

5             <netTcpRelayBinding>  

6                 <binding name="RelayEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00"  

7                     receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Buffered"  

8                     connectionMode="Relayed" maxBufferPoolSize="524288" maxBufferSize="65536"  

9                     maxConnections="10" maxReceivedMessageSize="65536">  

10                     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"  

11                         maxBytesPerRead="4096" maxNameTableCharCount="16384" />  

12                     <reliableSession ordered="true" inactivityTimeout="00:10:00"  

13                         enabled="false" />  

14                     <security mode="None" relayClientAuthenticationType="RelayAccessToken">  

15                         <transport protectionLevel="EncryptAndSign" />  

16                         <message clientCredentialType="Windows" algorithmSuite="Default" />  

17                     </security>  

18                 </binding>  

19             </netTcpRelayBinding>  

20         </bindings>  

21         <client>  

22             <endpoint address="sb://servicebus.windows.net/services/<MysolutionName>/WOService"  

23                 binding="netTcpRelayBinding" bindingConfiguration="RelayEndpoint"  

24                 contract="ServiceReference1.IWOService" name="RelayEndpoint" />  

25         </client>  

26     </system.serviceModel>  

27   <system.net>  

28     <defaultProxy useDefaultCredentials="true"></defaultProxy>  

29   </system.net>  

30 </configuration>  

Any help will be greatly appreciated.

Thanks,

Prashant.

Raimondb wrote re: Unable to generate a WCF proxy using svcutil but retrieving the wsdl works?
on 06-03-2009 11:23

Was the client side config autogenerated or handtweaked? Do you have code like this in your client?

// create the credentials object for the endpoint

TransportClientEndpointBehavior userNamePasswordServiceBusCredential = new TransportClientEndpointBehavior();

userNamePasswordServiceBusCredential.CredentialType = TransportClientCredentialType.UserNamePassword;

userNamePasswordServiceBusCredential.Credentials.UserName.UserName = solutionName;

userNamePasswordServiceBusCredential.Credentials.UserName.Password = solutionPassword;

// create the channel factory loading the configuration

ChannelFactory<IEchoChannel> channelFactory =

    new ChannelFactory<IEchoChannel>("RelayEndpoint", new EndpointAddress(serviceUri));

// apply the Service Bus credentials

channelFactory.Endpoint.Behaviors.Add(userNamePasswordServiceBusCredential);

The thing is that you need to explicitly authenticate in this style when going to the real servicebus. If you are not doing that, you're likely to get the mentioned security message.

See also for a complete sample: http://blogs.msdn.com/harishpa/archive/2008/11/07/my-first-azure-solution-myazureworldsolution-and-echo-sample-in-net-services-sdk.aspx

prashant wrote re: Unable to generate a WCF proxy using svcutil but retrieving the wsdl works?
on 09-03-2009 7:39

Hi,

Thanks a lot for reply.

I added credentials in client code using TransportClientEndpointBehavior class.

Now stuck at the weird exception,

--

The server at sb://servicebus.windows.net/services/ppSolution/WOService/ rejected the session-establishment request.

and inner exception --

"Error while reading message framing format at position 0 of stream (state: ReadingUpgradeRecord)"

Here is stack trace --

"\r\nServer stack trace: \r\n   at Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidatePreambleResponse(Byte[] buffer, Int32 count, ClientFramingDecoder decoder, Uri via)\r\n   at Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)\r\n   at Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)\r\n   at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)\r\n   at Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)\r\n   at Microsoft.ServiceBus.Channels.CommunicationObject.Open(TimeSpan timeout)\r\n   at Microsoft.ServiceBus.Channels.LayeredChannel`1.OnOpen(TimeSpan timeout)\r\n   at Microsoft.ServiceBus.Channels.CommunicationObject.Open(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.CommunicationObject.Open()\r\n\r\nException rethrown at [0]: \r\n   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n   at System.ServiceModel.ICommunicationObject.Open()\r\n   at GRSClient.Program.Main(String[] args) in C:\\Program Files\\Microsoft .NET Services (Dec 2008 CTP) SDK\\Samples\\ServiceBus\\ExploringFeatures\\RelayAuthentication\\Username\\MySample\\GRSClient\\Program.cs:line 39\r\n   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.ThreadHelper.ThreadStart()"

Thanks a lot in anticipation,

Prashant.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Powered by Community Server (Commercial Edition), by Telligent Systems