Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Calling webservice - Protocolexception - 404
38 replies. Latest Post by Tuizi on August 11, 2008.
(0)
klukkluk
Member
0 points
8 Posts
06-22-2008 7:34 PM |
I'm trying to access a webservice in my silverlight project. The webservice works fine, calling the webservice with different parameters gives me exactly the result I want, but with this set of parameters, I get a "ProtocolException was unhandled by user code" "The remote server returned an unexpected response (404) Not Found".
Setting a breakpoint in the service, I see there's indeed nothing wrong with the service, the breakpoint gets hit, and the right response is returned. After googling a bit on the subject, a possible reson might be the length of the response. So I modified the web.config to include:
<binding name="LargeBuffer" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"><readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /></binding>
And of course I set my bindingconfiguration to this. Still the same problem though. I tried using the web development helper to see what's going on, but this plugin throws a .NET exception:
************** Exception Text **************System.NullReferenceException: Object reference not set to an instance of an object. at nStuff.WebDevHelper.UserInterface.HttpTools.HttpLogConsole.ProcessNewItems()
So no help there either. Does anyone have any suggestions left about what's wrong here?
sladapter
All-Star
17441 points
3,172 Posts
06-22-2008 9:43 PM |
1) Are you doing cross-domain call? If yes, have you updated your clientaccesspolicy file?
2) If you do not think it is cross-domain call. Have you checked url for the endpoint of your service in your ServiceReference.ClientConfig file? Is the Port# in that url the same as the port# in your page url? Or you set the Service URL in your code?
3) Did you get the error only when you trying to send large data back to your WebService? If not, your LargeBuffer binding change won't help you. If yes, take a look at this thread. Follow the steps I posted in my last post there to config your Web.config and ServiceReference.ClientConfig file:
http://silverlight.net/forums/p/18466/63010.aspx#63010
06-23-2008 5:31 AM |
Still no luck, the 2nd time my webservice gets called, it still fails. It's no cross-domain call, and it's no port problem, because in that case the first call would have failed as well. I've modified the ClientConfig like you suggested, but still the same problem :(
SteveWong
Contributor
6343 points
1,281 Posts
06-23-2008 8:20 AM |
can you paste your clientaccesspolicy.xml and the web.config and ServiceReference.ClientConfig here?
06-23-2008 9:11 AM |
klukkluk:Still no luck, the 2nd time my webservice gets called, it still fails. It's no cross-domain call, and it's no port problem, because in that case the first call would have failed as well. I've modified the ClientConfig like you suggested, but still the same problem :(
lewisb
217 points
82 Posts
06-23-2008 11:58 AM |
Is the first call to the webservice passing/returning a some primative data type(s) and the second call using some complex data type? If so, there may be some sort of serialization error.
06-23-2008 1:26 PM |
@SteveWong:
I don't have a clientaccesspolicy file, this is my clientconfig:
<configuration><system.serviceModel><client><endpoint address="http://localhost:58139/MasterDetail.svc" binding="basicHttpBinding"bindingConfiguration="BasicHttpBinding_MasterDetail" contract="SLWeb.ServiceReference.MasterDetail"name="BasicHttpBinding_MasterDetail" /></client><bindings><basicHttpBinding><binding name="BasicHttpBinding_MasterDetail" maxBufferSize="2147483647"maxReceivedMessageSize="2147483647"><security mode="None" /></binding></basicHttpBinding></bindings></system.serviceModel></configuration>
@sladapter:
Yes, I have the webservice working, but only with a certain set of 'request' parameters. With a 2nd set, a different response is returned. And this one fails.
06-23-2008 2:16 PM |
klukkluk:Yes, I have the webservice working, but only with a certain set of 'request' parameters. With a 2nd set, a different response is returned. And this one fails.
What is your second set of parameter that not working? Could you show your the WebService function signature?
06-23-2008 2:21 PM |
Also, what are the return types of both calls? Bool, int, some complex object?
06-23-2008 3:08 PM |
The return type of my webmethod is a complex type.
06-23-2008 3:15 PM |
You tagged all your complex type of data as [DataContract]? You sure it's not a serialization problem?
mebjen
82 points
99 Posts
06-23-2008 3:17 PM |
I am having similiar issues, only mine isn't intermittant - I get the 404 error on the first try every time - via webDevelopmentHelp I get a 404 status on URL - http://ws.cdyne.com/clientaccesspolicky.xml - here is my clientaccesspolicy.xml file.
<?xml version="1.0" encoding="utf-8"?><access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access></access-policy>
06-23-2008 3:20 PM |
mebjen,
Check your clientaccesspolicky.xml file name. it should be clientaccesspolicy.xml.
Where did you put your clientaccesspolicy.xml file? At inetput\wwwroot?
06-23-2008 3:39 PM |
sladapter,
good catch - that was just a typo on my end. I went back and checked - it is clientaccesspolicy.xml. Yes, my clientaccesspolicy is located in C:\Inetpub\wwwroot
Also, I should mention that this serviceReference worked great in SL2B1 -
06-23-2008 3:57 PM |
Check the url for your service end point in your ServiceReferences.ClientConfig.
Show us the code you make your WebService call.
Also make sure you are running in http mode not in File mode. (check your page url when you run your page)
06-23-2008 4:24 PM |
serviceReference.ClientConfig - endPoint
<
code to call webService -
Dim
yes - diffently running in http mode -
06-23-2008 4:41 PM |
I should have include:
06-23-2008 5:34 PM |
1) You should change the order of your call. Add serviceCompleted event handler before you call the service. Otherwise your code won't hit Service completed event handler code. (this change won't fix your 404 error)
AddHandler verEmail.VerifyEmailCompleted, AddressOf verEmail_Completed
verEmail.VerifyEmailAsync(mailIn, strLiscenseKey)
2) I saw you put the URL in the code and create binding in the code, so you are by-passing the ClientConfig reading. That is OK. We do not have to worry about what's in the ClientConfig in this case.
3) Is "ws.sdyne.com" the server you put your clientaccesspolicy.xml file?
4) What is the size of your mailIn string? Could it be greater than 8200 chars?
06-23-2008 6:23 PM |
1 - OK // but prior to sl2b2 when everything was working, during debug I was able to 'step-into' all aspects of this related code - in fact, it does hit service completed event handle code because that is where other events fire and if it didn't reach service completed - I would have other issues to address.
2- . . . .
3 - ws.cdyne.com is the web service - http://ws.cdyne.com
4 - mailin is just you typical email address (someone@somewhere.com)
06-23-2008 8:53 PM |
Everything should be fine then. Can you access http://ws.cdyne.com/clientaccesspolicy.xml by putting the URL in the browser?
06-23-2008 11:09 PM |
I wish everything was fine - yes, I access by putting the URL in the browser. I still get the ProtocolException - The remote server returned an unexpected response: (404) Not Found. Highlighting/pointing at _result. This function is in Reference.vb
06-23-2008 11:30 PM |
Hi, I feel your pain. I just don't have any new clue on where the problem could be. Is it possible to put the Service code under your Web project so you can make non cross-domain call to see if it is working? You want to make sure it is not a cross-domain issue first before you calling the remote service.
06-24-2008 12:32 AM |
OK - this has been an all day hair-puller. I've noticed from all my searches that others are or have had similar problems - but I'm not seeing any definitive answers. So - I thought I would try and create a 'new/fresh' sl2b2 project and add a serviceReference - to test. After I had my cdyne reference (http://ws.cdyne.com/emailverify/emailvernotestemail.asmx) named cdyneServRef - and the following one line of code:
It builds without error / but I get the following Error - when I try and run it.
System.InvalidOperationException was unhandled by user code Message="ConfigUnrecognizedElement" StackTrace: at System.ServiceModel.Configuration.BindingsSection.ReadXml(XmlReader reader) at System.ServiceModel.Configuration.ServiceModelSectionGroup.ReadXml(XmlReader reader) at System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup() at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Current() at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard) at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName) at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory() at System.ServiceModel.EndpointTrait`1.CreateChannelFactory() at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait) at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef() at System.ServiceModel.ClientBase`1..ctor() at sl2b2_webServiceTest.cdyneServRef.EmailVerNoTestEmailSoapClient..ctor() at sl2b2_webServiceTest.Page..ctor() at sl2b2_webServiceTest.App.Application_Startup(Object o, StartupEventArgs e) at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) InnerException:
06-24-2008 3:32 AM |
Well, I still haven't solved my issue either.
Is there a way to check if the response from my webservice gets serialized properly?
skm.soft...
196 points
216 Posts
06-24-2008 7:31 AM |
Hi,
There is simple solution if every function working fine in your's service code, or sometime this error may be also due to some database error.
Try the following
Delete the service refrence file from the project.
Create a new service reference file with same name(i.e of deleted)
and run the application again,
Sachin Mukhija
06-24-2008 7:32 AM |
06-24-2008 8:45 AM |
Hi Sachin,
I actually started a new SL2B2 project, here are the steps I took:
In this SL app there is 1 textBox and 1 button:
Ok, so that's it - now when I run it - I receive the following error after a btnClick -
System.ServiceModel.ProtocolException was unhandled by user code Message="The remote server returned an unexpected response: (404) Not Found." StackTrace: at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result) at sl2b2_webServiceTest.cdyneServRef.EmailVerNoTestEmailSoapClient.EmailVerNoTestEmailSoapClientChannel.EndVerifyEmail(IAsyncResult result) at sl2b2_webServiceTest.cdyneServRef.EmailVerNoTestEmailSoapClient.cdyneServRef_EmailVerNoTestEmailSoap_EndVerifyEmail(IAsyncResult result) at sl2b2_webServiceTest.cdyneServRef.EmailVerNoTestEmailSoapClient.OnEndVerifyEmail(IAsyncResult result) at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result) InnerException:
06-24-2008 9:35 AM |
Sachin,
Already tried that...
06-24-2008 9:39 AM |
mebjen:OK - this has been an all day hair-puller. I've noticed from all my searches that others are or have had similar problems - but I'm not seeing any definitive answers. So - I thought I would try and create a 'new/fresh' sl2b2 project and add a serviceReference - to test. After I had my cdyne reference (http://ws.cdyne.com/emailverify/emailvernotestemail.asmx) named cdyneServRef - and the following one line of code: Private verEmail As New cdyneServRef.EmailVerNoTestEmailSoapClient It builds without error / but I get the following Error - when I try and run it. System.InvalidOperationException was unhandled by user code Message="ConfigUnrecognizedElement"
Private verEmail As New cdyneServRef.EmailVerNoTestEmailSoapClient
System.InvalidOperationException was unhandled by user code Message="ConfigUnrecognizedElement"
mb,
I know this error. This error is caused by some invalid tag in your ClientConfig file.
Check your ClientConfig file to see if you have a Tag called CustomBinding? For some reason if your service is asmx service, when creating a ServiceReference, VS put this CustomBinding tag into the ClientConfig file. But it is neither used nor it's a valid. At least 2 people already had this probelm. Just remove that tag should make this error go away.
I don't know if anybody has already reported this bug or not. You can try to report it in the Bug forum if you find this is the case.
See this Rui-Marinho 's problem in this thread: http://silverlight.net/forums/p/17500/60453.aspx#60453
06-24-2008 4:09 PM |
OK - after a day and half and working closely w/sladapter, we were able to figure out the problem. CDYNE is a public webService used for checking the validity of an email address. In SL2B1 everything worked fine - its wasn't until SL2B2 that the problems appeared. It was because the neither the clientaccesspolicy file nor the crossdomain file had been updated to reflect the minor policy changes in SL2B2. Once CDYNE updated the files the ProtocolException-404 went away. Bottom line, if you are using a public web service - make sure there policy files are updated to support SL2B2.
peterral...
21 points
11 Posts
07-16-2008 11:08 AM |
Hi, I am also having a problem with the 404 error....basically I am trying to implement sladapter's solution to displaying a dataset in my datagrid (found here: http://silverlight.net/forums/p/16733/69252.aspx#69252) as I need to display dynamic data that I will not always know the exact structure for, therefore this solution is perfect, apart from I am writing it in vb. Now everything appears to be working absolutely fine and I have converted it into vb nicely and I can see the results when I put it into debug, but as soon as I try to pass my result within the object over my silverlight wcf service to my code behind the xaml it hits the 404 error in my reference.vb. I have tried all of the solutions suggested in this thread, but with no success, does anybody have any other suggestions please?
07-16-2008 11:29 AM |
When you say everything is working fine does that mean you get the data displayed? So you already had the data coming from WCF service working, right? When do you get 404 error?
07-16-2008 11:46 AM |
Thanks for the speedy reply! I can see the data populating the object that I create within my web service.svc.vb, I'm stepping through it with debug watching it populate, but as soon as it tries to return the result from the service to the silverlight it gets stuck in the transfer and throws up the 404 error. It happens in my Reference.vb in this function:
_args(0) = CRMTableName
_args(1) = ErrorStr
CRMTableName =
it always highlights the object at the end of this line: Dim _result As Object = CType(MyBase.EndInvoke("GetOneRecCRMTable", _args, result),Object)
07-16-2008 11:58 AM |
So you are hitting the service that means it's not a connection problem. The problem is when you trying to return the data. What data you are trying to return? I assume you are trying to return a DataSetData back since you said you are using my demo code. Could you post your VB code of your DataSetData object?
Let's do this. Could you move your question to the original "Dispaly DataSet in DataGrid" thread since I don't think this is a WCF connection issue. I'll answer it there. This thread is getting too long.
07-16-2008 12:09 PM |
Yes the service seems to be working and has been in the past until I started trying to pass the datasetdata over, I'll move the question and post the code in the other thread for you. Thank you.
07-24-2008 5:54 AM |
I'm still struggling with this issue...
I tried putting base.EndInvoke("MethodName", _args, result) in my quicklaunch window (the line where this error occurs). When I inspect the base object in the quicklaunch window, it shows me: {System.InvalidOperationException: End has already been called on this asynchronous result object. at System.ServiceModel.ASyncResult.End[TAsyncResult](IAsyncResult result)
Does this give anyone any clues about what's going wrong here? I can't google much on this error.
07-24-2008 10:36 AM |
I asked you to post your Service method and your return Object defination ( you said it was a complex type) that you are having problem with. But you never did.
Nobody knows what is going on in your code. I think your problem is definitely not connection (cross-domain issue) issue. It's a data serialization issue.
07-24-2008 11:18 AM |
Okay, it's a bit hard to explain, but i'll give it a try.
I'm trying to create a master detail scenario in silverlight. The master part, the screen with a datagrid, works fine, it's the detail part that doesn't work. Both master and detail screens use the same webservice, MasterDetail.svc. This returns a Response object. This Response object has column definitions and rows. Each row is a collection of cells, which are objects. I have defined the cells as objects because I want to create a generic solution for displaying data from any databasetable in my database. So when the databasecolumn can be mapped to an int, this results in the webservice to generate an <anytype xsi:type="xsd:int"> for this cell. Same for strings etc. Works perfectly for the master scenario.
In the detail scenario, the same Response object is returned, now with all columns from the current table. The cells collection is filled much like in the master scenario. But in this case it's also possible that the current databasecolumn is a relationship to another table. In the detailscreen, this should become a combobox. To fill this combobox, I need the data in the referenced table in the response object. So what I do is create another Response object, with column definitions and rows, and put this object in the cells collection. This gets serialized as: <anytype xsi:type="Response">. So, a Response object inside a Response object.
I have put a bit of logging inside the webservice, an xmlserializer which writes to a new file on each request. The response gets written to file perfectly each time in both scenarios. But the detail scenario still raises the above exception in the reference.cs unfortunately. I also use Nukhil's web development helper to see what's going on. This logs the master response perfectly, but when the exception in detail mode is raised, this tool also raises an exception, so not much help there.
I appreciate your effort to look into this very much. If you need some logging files or some further explanation just let me know.
Tuizi
177 points
90 Posts
08-11-2008 2:54 PM |
Hello, Did you find a solution for this problem? Because, me, I just created a Service with a method named "DoWork" who return an int, and when I try to use this fonction from my silverlight application I get "ProtocolException: The remote server returned an unexpected response: (404) Not Found."