PDA

Click to See Complete Forum and Search --> : [RESOLVED] WCF Service problems


Hamish
Feb 19th, 2009, 10:39 AM
I can't seem to get even the simplest WCF Service working. May be something with my setup, I'm hoping you guys know. My service opens without errors in IE when I press Ctrl+F5. If I copy the URL, start wcftestclient.exe and paste the URL, I get a nice interface with the operations defined in my ServiceContract. So far so good. When I try to use one of the operations though, I get the following error message:
"The remote server returned an unexpected response: (400) Bad Request."

I'm running the Windows 7 Beta, could that be the problem? Or is this something completely different. I'm lost here, so any help is appreciated.

mendhak
Feb 19th, 2009, 10:42 AM
We'll need to see code, WCF problems cannot be easily solved without looking at code and the relevant web.config sections.

Hamish
Feb 19th, 2009, 10:45 AM
Do you want all of it, or any part in particualr?

mendhak
Feb 19th, 2009, 11:09 AM
From the config file, all the <endpoint> nodes, the <behavior> nodes and related configuration nodes.

From the code... just the method you're trying to invoke and the code you're using to try and invoke it(client). I think this may be more of a reference problem than a code problem though.

Hamish
Feb 19th, 2009, 11:17 AM
IChatService.vb
<ServiceContract()> _
Public Interface IChatService

<OperationContract()> _
Sub SubmitMessage(ByVal value As ChatMessage)

<OperationContract()> _
Function GetMessages() As List(Of ChatMessage)

End Interface

<DataContract()> _
Public Class ChatMessage

<DataMember()> _
Public Sender As String

<DataMember()> _
Public MessageText As String

End Class


ChatService.svc.vb
Public Class ChatService
Implements IChatService

Private _Messages As List(Of ChatMessage)

Public Function GetMessages() As System.Collections.Generic.List(Of ChatMessage) Implements IChatService.GetMessages
Return _Messages
End Function

Public Sub SubmitMessage(ByVal value As ChatMessage) Implements IChatService.SubmitMessage
_Messages.Add(value)
End Sub
End Class


ChatService.svc
<%@ ServiceHost Language="VB" Debug="true" Service="ChatServiceLibrary.ChatService" CodeBehind="ChatServiceLibrary.ChatService.svc.vb" %>


From Web.config
<system.serviceModel>
<bindings />
<client>
<endpoint binding="wsHttpBinding" bindingConfiguration="" contract="ChatServiceLibrary.IChatService"
name="WS" />
</client>
<services>
<service behaviorConfiguration="ChatServiceLibrary.ChatServiceBehavior"
name="ChatServiceLibrary.ChatService">
<endpoint address="mex" binding="mexHttpBinding" name="MEX" contract="IMetadataExchange" />
<endpoint binding="wsHttpBinding" bindingConfiguration="" name="WS" contract="ChatServiceLibrary.IChatService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ChatServiceLibrary.ChatServiceBehavior">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

mendhak
Feb 19th, 2009, 11:47 AM
OK, so far everything looks good, and you're right, that should work. How are you invoking the web service?

Hamish
Feb 19th, 2009, 12:18 PM
In Visual Web Developer I press Ctrl+F5 to run the service, this will display the address of the service on a web page. I then run wcftestclient.exe and add the service using the address from the web page.

Hamish
Feb 19th, 2009, 01:16 PM
Found this (http://community.softteq.com/blogs/nick/archive/2009/01/19/wcf-service-running-under-windows-7.aspx)
Seems I was right about it being a Windows 7 issue. :(

mendhak
Feb 19th, 2009, 06:39 PM
Odd, if that worked for you.

What about basicHttpBinding then? That should work regardless.

Hamish
Feb 20th, 2009, 06:23 AM
It works, but I decided to do basicHttpBinding for now, cause that works as well.

mendhak
Feb 20th, 2009, 08:11 AM
Alright, sorry if my answers seem vague or unsatisfactory to you, WCF questions are usually quite hard to troubleshoot because of its inherent nature - a lot of code needs to be shown and the web.config is extremely important because they've abstracted it so that the XML does all the heavy lifting for you. You sometimes end up in these strange scenarios which are caused by things that you had never imagined before. :D

Hamish
Feb 20th, 2009, 08:18 AM
I'm very happy with your answers. I mostly post here to get directions anyway. Don't want someone to solve my problems for me (well, sometimes I do!), just need a nudge in the right direction. It's only a hobby for me, nothing crucially important or on a deadline or anything. :)
You helped me a lot by asking for that section of web.config. It made me take a better look at that file, and I now understand what the svcconfigeditor tool does. So thanks again! :bigyello: