Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Debug Silverlight Webservice
36 replies. Latest Post by Kbalz on August 20, 2008.
(0)
Kbalz
Member
213 points
185 Posts
08-18-2008 9:24 AM |
My silverlight applications can call my webservice just fine, but my webservice is returning some unexpected data. I need to step through the logic that is happening on the service. But when I debug the service call, my silverlight app calls the Async method, then waits for the service to finish. I would like it VS 2008 to hit break points in my service class that I've placed. Is this possible?
Leonid A...
636 points
137 Posts
08-18-2008 9:34 AM |
You can open your SL site without debugging it in VS, so you can debug you webservice in VS. Or you can use File -> Open -> file (your service.cs file) put breakpoint and start debugging.
Skyrunner
Contributor
2489 points
485 Posts
08-18-2008 9:43 AM |
It's easier when your SL project and WS project are in the same solution, you can debug both.
microsof...
2890 points
564 Posts
08-18-2008 9:44 AM |
Yes, you can do this by setting breakpoint in the Service class.Do Remember: If you are debugging for more than the time-out time, then this will through ProtocolException.
08-18-2008 9:59 AM |
Website with SilverlightWebservice and SilverlightApplication are in same solution.
The default startup project for the solution is the website. The when debuging, it launches the SilverlightTestPage.aspx. I put my first break point in the Silverlight Application, where I call the webservice.
BasicHttpBinding binder = new BasicHttpBinding();binder.MaxBufferSize = 2147483647;binder.MaxReceivedMessageSize = 2147483647;EndpointAddress endpoint = new EndpointAddress("http://....SilverlightService.svc");SilverlightServiceClient proxy = new SilverlightServiceClient(binder, endpoint);proxy.WebCallCompleted += new EventHandler(proxy_WebCallCompleted);proxy.WebCallAsync(param1);
Once it hits this breakpoint, I step and it opens the Reference.cs file and hits two methods in this file. Then I keep steping through, my silverlight app completes the method where my call occurs. The app sits for about 20 seconds, then the next line the debugger hits is still in the silverlight app
void proxy_WebCallCompleted(object sender, WebCallCompletedEventArgs e){ //...}
Now I have several break points in my service, that never hit hit during that 20 seconds. What am I doing wrong?
08-18-2008 10:06 AM |
If you place a BP in the WS class in your WS project, do you hit it?
08-18-2008 10:14 AM |
Maybe that is my problem.. I have no dedicated 'webservice project'. I have my Website project, and in a subfolder I keep all of my svc files. This seemed to work OK so I left it alone.
rajesh s...
2314 points
505 Posts
08-18-2008 10:25 AM |
I think you have not enabled Silverlight Debugging. Right Click on your web project ==> Properties ==> Start Options ==> here you have to enable the debugging of silverlight app.
08-18-2008 10:48 AM |
Right clicked my web project -> Properties. There is no 'Start Options' but under Web -> There are four checkboxes for debuggers, Silverlight was already checked along with ASP.NET. Native Code and SQL Server were not checked.
08-18-2008 10:50 AM |
And if you place a BP into your xxxService.svc.cs did you hit it?
08-18-2008 10:53 AM |
No I haven't hit any breakpoints in my service.svc.cs file as of yet.
08-18-2008 4:27 PM |
So everyone is able to hit breakpoints in the service svc.cs files ? I still can not get them to hit, but I know they are being called.
The entire Application is on a server share, not my local machine.. does this matter? When I go in debug mode, it starts the developement server on my local machine and runs everything from there.. but I think the service calls still go directly to www..../service.svc. since that is what is hardcoded in the proxy's address.
sladapter
All-Star
17441 points
3,172 Posts
08-18-2008 4:35 PM |
Just set a break point in you Web Service code under your Web Project then run your Silverlight app. You can debug both Silverlight code and Service code at the same time as long as they are running in the same solution and the test page (YourTestPage.html/aspx) and Service are under the same Web Project. At your Silverlight service call, set a break point, when that break point is hit, just hit F5 let it continue. It should hit your Service break point if your call can connect to your service. If you can not hit your Service code, it usually means it did not even make the connection.
08-18-2008 4:42 PM |
Right that is what I've been trying to the letter. Everything is in one single solution. I know the service is being called because it is adding rows to my database, and returning data to my silverlight applications.
08-18-2008 4:47 PM |
Is the Web Service running under the same project as your page?
08-18-2008 4:49 PM |
Kbalz:The entire Application is on a server share, not my local machine.. does this matter? When I go in debug mode, it starts the developement server on my local machine and runs everything from there.. but I think the service calls still go directly to www..../service.svc. since that is what is hardcoded in the proxy's address.
Wait, are you calling a service running from a remote server? Of course it won't hit the break point on your machine. It's not even running at your machine. I thought you said they are running from the same solution.
08-18-2008 5:07 PM |
Everything is in the same solution. The solution is on my webserver (on my network).. On the webserver, the website is running in IIS 6.0, so when I run the the site, I go www.mydomain.com/silverlight/TestPage.aspx my services are at www.mydomain.com/webservice/SilverlightService.svc/
In my silverlight application, the proxies are hardcoded like this:
BasicHttpBinding
When I debug, everything runs on my machine on the development server like http://mybox:1010/silverlight/TestPage.aspx/
I'm sure you're right that they are still calling the hardcoded mydomain.com/ and NOT the service on my box. I guess my question is now, what should I be putting in the EndpointAddress, so that it calls the correct SVC file no matter if I'm in debugg or not?
08-18-2008 5:17 PM |
When you debug, if you run http://mybox:1010/silverlight/TestPage.aspx, The Silverlight code is running from your machine (your machine is the client machine), But your Silverlight is calling a service which is running at www.mydomain.com, not from your Dev Server. The service is not running from your machine. So there is no way you can hit the break point you set on your solution.
If you want to debug the Service, you need to make sure the Service is also running on your Dev Server. Change the following code to this:
EndpointAddress endpoint = new EndpointAddress(http://www.mydomain.com/webservice/SilverlightService.svc);
EndpointAddress endpoint = new EndpointAddress(new Uri(Application.Current.Host.Source, "./WebService/SilverlightService.svc"));
You do not need to change this code back when you deploy, this code should serve you well in both dev Server and IIS.
08-19-2008 8:16 AM |
It didn't work, so I put this in a textBox to see the address it was requesting the service
When run in non-debug mode by going to http://www.mydomain.com/silverlight/TestPage.aspx the code you posted gives this URI :
http://www.mydomain.com/ClientBin/NewInterface.xap./Webservice/SilverlightService.svc
When I run in debug mode, it requests this URI
http://localhost:2098/ClientBin/WebService/SilverlightService.svc
08-19-2008 9:41 AM |
It works now, I needed ../Webservice/ instead of ./Webservice for the relative part of the URI
08-19-2008 9:53 AM |
Well the URI is correct for both debug and nondebug without switching anything, but while in debug I'm getting this error:
Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [].
When trying to browse to the SVC file in the browser, I also get that error : http://localhost:2098/Webservice/SilverlightService.svc
08-19-2008 9:59 AM |
What is your code for calling the Service?
08-19-2008 11:01 AM |
The actual service call is coming from a Silverlight Class Library. I had four silverlight projects all accessing webservices, so I had all the webservice calls in one SL Class library project. The SL Class library is also in the same solution, it doesn't generate a XAP file however (probably inbeds in the referencing xaps).
So from the Sivlerlight User Control:
public partial class Page : UserControl { public Page() { InitializeComponent(); SL_Library.webCaller web = new SL_Library.webCaller(); webCaller.CallService(1); } }
From the SL_Library
1 namespace SL_Library 2 { 3 public class webCaller 4 { 5 public Uri APM_URI = new Uri(Application.Current.Host.Source, "../WebService/SilverlightService.svc"); 6 7 public webCaller() 8 { 9 10 } 11 12 public void CallService(int arg) 13 { 14 BasicHttpBinding binder = new BasicHttpBinding(); 15 binder.MaxBufferSize = 2147483647; 16 binder.MaxReceivedMessageSize = 2147483647; 17 18 EndpointAddress endpoint = new EndpointAddress(APM_URI); 19 20 SilverlightServiceClient proxy = new SilverlightServiceClient(binder, endpoint); 21 proxy.UseDataCompleted += new EventHandler(proxy_UseDataCompleted); 22 proxy.UseDataAsync(arg); 23 } 24 25 ...... 26 } 27 }
08-19-2008 11:04 AM |
So SL_Library project has the Service Reference.. when I right click properties for the SilverlightServiceReference, ==> Configure Service Reference,
Under the Client section, the Address is coded like this:
http://www.mydomain.com/WebService/SilverlightService.svc
So perhaps when I added my service reference, I did it incorrectly..?
08-19-2008 11:21 AM |
You code looks right. When you set EndpointAddress in your code, you by-pass the ServiceReferences.ClientConfig reading. So now we do not care what you set in the ServiceReferences.ClientConfig file.
But you should be able to access your service using the URL http://localhost:2098/Webservice/SilverlightService.svc in a browser. If you got error, could you try to make sure this is the correct URL.
Could you try to add the ServiceReference point to the Service on your solution (not remote machine). It should give you the correct URL used by the Dev Server. Check that URL to see if it is the same as the one above.
08-19-2008 11:39 AM |
When I go to:
http://localhost:2098/Webservice/
I see the SilverlightService.svc and SilverlightService.svc.cs files listed in the browser (directory browsing seems to be on by default)
When I click to the .svc file, I get the error I posted earlier:
Server Error in '/' Application.Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [].
The APM_URI variable is returning the correct location when I run debug, it is pointing the service on my locahost, http://localhost:2098/Webservice/SilverlightService.svc
08-19-2008 11:56 AM |
Check your Web.config. Use WCF configuration Editor to open the Web.config file. Find the Endpoint for your Service. Is the binding set to BasicHttpBinding? What is the BindingConfiguration.
If you still can not make it work. Try to add another Silverlight Enabled WCF service. Just make a simple DoWork function. Add ServiceReferenece to your Silverlgiht and try to access this service see if you can do it. Set a break point on the DoWork function and see if you hit the break point.
If everything works fine, copy your real Service code from you SilverlightService.svc to this newly created service. Make sure you do it one small step at a time and test every step. When everything works, delete your old service.
08-19-2008 1:18 PM |
sladapter:Check your Web.config. Use WCF configuration Editor to open the Web.config file. Find the Endpoint for your Service. Is the binding set to BasicHttpBinding? What is the BindingConfiguration.
For my service, there are two endpoints.
1st Endpoint, (Empty Name), the address is blank, the Binding is basicHttpBinding, the Binding Configuration is (Default) Click to Create and the Contract is WebService.SilverlightService
2nd Endpoint, (Empty Name), the address is mex, the Binding is mexHttpBinding, the Binding Configuration is (Default) Click to Create and the Contract is IMetadataExchange
sladapter:If you still can not make it work. Try to add another Silverlight Enabled WCF service. Just make a simple DoWork function. Add ServiceReferenece to your Silverlgiht and try to access this service see if you can do it. Set a break point on the DoWork function and see if you hit the break point.
I created a new Silverlight Enabled WCF service, compared the two in the WCF Config Editor, they look the same except for the Contract of course. The service launches in the browser remotely just fine at http://www.domain.com/Webservice/Service1.svc/ but will not open on the localhost.. opening http://localhost:2098/Webservice/Service1.svc produces the same error. When I call the local service in debug mode, I get an error 404 not found.
08-19-2008 1:36 PM |
This may be important:
here is part of my WebConfig:
<
</
08-19-2008 3:31 PM |
The above lines definatly are affecting this error.. if I changed the prefix to be localhost instead of the domain, then the localhost services work, however the domain services do not. I've tried lots of combinations with this section, what should it look like?
08-19-2008 10:15 PM |
You only need <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
Take off the prefix line and try it. I don't know why you need add that line in the config. My services do not have that line and all work fine.
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters><add prefix=http://www.domain.com /></baseAddressPrefixFilters>
<add prefix=http://www.domain.com />
</serviceHostingEnvironment>
08-20-2008 9:14 AM |
Sladapter, I think I added those lines based on something I read online.. it didn't end up working. Anyways, I've removed the lines and only have <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
However now my services are not working on the remote server (www.domain.com) after I remove those lines. I think my services have somehow become corrupt, how can I fully remove ALL service references from my web site project? I can re add my classes after I get the basic DoWork working for debugging. Do I just remove the entire section from the web.config or is there more to do?
08-20-2008 9:50 AM |
NOW I remember why I added those lines in the first place.. in IIS (6.0) on my webserver (Windows Server 2003), under my website right click properties ==> Web Site Tab ==> Advanced ==> I have multiple identities for this website.. two host headers.. one for www.domain.com and a second for domain.com
When I added the second host header to the list, my WCF services quit working.. so by adding that base prefix, it directed the WCF to use the correct host header.
08-20-2008 9:57 AM |
I see. But you might want take them off for debugging. When you are ready for deploy, you can add those lines back.
When debugging, you are not pointing your service on www.domain.com, you are pointing the service on your local machine.
08-20-2008 10:02 AM |
Yep I will do that. I've made a change to my IIS that no longer requires having two host headers for one site as well, so I should be able to have my services section of the web.config in its default state.
08-20-2008 10:04 AM |
Kbalz:I think my services have somehow become corrupt, how can I fully remove ALL service references from my web site project? I can re add my classes after I get the basic DoWork working for debugging. Do I just remove the entire section from the web.config or is there more to do?
I think my services have somehow become corrupt, how can I fully remove ALL service references from my web site project? I can re add my classes after I get the basic DoWork working for debugging. Do I just remove the entire section from the web.config or is there more to do?
Use WCF Configuration Editor to edit your Web.config is a better way. You can delete the service or config service using this editor. It's better than editing the config file directly. It's really hard to read or change the config files line by line. One typo could mess the whole thing up.
08-20-2008 10:08 AM |
Breakpoints are now being hit while debugging my .svc files. Thanks for your help !!