Skip to main content

Microsoft Silverlight

Answered Question Add web reference problem(silverlight 2.0)RSS Feed

(1)

Kostja
Kostja

Member

Member

38 points

16 Posts

Add web reference problem(silverlight 2.0)

Hi! I have a problem
I build client server application on silverlight  2.0
I implement webService project - ChatService and asp.net project Chat.Display project
I need to use in Chat.Display the webService  ChatService
How can i add web reference to Chat.Display project?
I can just Add Service Link not Add web Reference?

Thanks 

CraigN
CraigN

Member

Member

352 points

89 Posts

Answered Question

Re: Add web reference problem(silverlight 2.0)

Use the "Add Service Reference" function, it does effectively the same thing as the old familiar "Add Web Reference" used to do for other project types. :)

Microsoft Xbox MVP

Kostja
Kostja

Member

Member

38 points

16 Posts

Answered Question

Re: Add web reference problem(silverlight 2.0)

Understood
I add web service reference to my project

web service contain just one method

[WebMethod]
public string HelloWorld()
{
    return "Hello World";
}
 

Could you tell me or give me the code sample how to use this method from Page.xaml.cs code file please Smile

Thank you very much!
 

CraigN
CraigN

Member

Member

352 points

89 Posts

Answered Question

Re: Add web reference problem(silverlight 2.0)

 Assuming your Web service in your web project is named HelloWebService you'd do the following from your Silverlight Application project:

  1. Build the Web service project.
  2. Click "Add Service Reference".
  3. Click the Discover button and choose "Services in Solution".
  4. Select HelloWebService.asmx.
  5. Enter a Namespace, e.g. "Testing".
  6. Click OK.
  7. Goto your Page.xaml.cs file and add a using class for your namespace.
  8. In a method or even the constructor Page() enter: "HelloWebServiceSoapClient client = new HelloWebServiceSoapClient();"
  9. This will instantiate an instance of the proxy class.
  10. Next assign a callback event handler like this: "client.HelloWorldCompleted += HelloWorldCompletedEventArgs>(ClientHelloWorldCompleted);" Use the code generator helper for this. i.e. press TAB.
  11. Call the method asynchronously: "client.HelloWorldAsync();"
  12. Then in the ClientHelloWorldCompleted method inspect the e.Result.
Simple isn't it?

Microsoft Xbox MVP

Kostja
Kostja

Member

Member

38 points

16 Posts

Answered Question

Re: Add web reference problem(silverlight 2.0)

Yes it simpleSmile
But i have some error 

 

An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code
Additional information: [UnexpectedHttpResponseCode]
Arguments:Not Found
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.2&File=System.ServiceModel.dll&Key=UnexpectedHttpResponseCode

 

Code:

public Page()
        {
            InitializeComponent();


            ChatService.ChatSoapClient client = new Addition.Chat.Silverlight.ChatService.ChatSoapClient();           

            client.HelloWorldCompleted += new EventHandler<Addition.Chat.Silverlight.ChatService.HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
            client.HelloWorldAsync();
        }
        //----------------------------------------------------------------------------------------------------------------
        void client_HelloWorldCompleted(object sender, Addition.Chat.Silverlight.ChatService.HelloWorldCompletedEventArgs e)
        {
            String s = "";
        }

Do you have any idea?

Thanks
 

CraigN
CraigN

Member

Member

352 points

89 Posts

Answered Question

Re: Add web reference problem(silverlight 2.0)

That sounds like you are trying to call cross-domain. Create a clientaccesspolicy.xml file as per here (http://msdn2.microsoft.com/en-us/library/cc197955(VS.95).aspx) and put it in the root of the web site. Note this is not in the web service directory, but rather the root of the whole site. You should be able to access it using your web browser.

Does that solve the problem?
 

Microsoft Xbox MVP

Kostja
Kostja

Member

Member

38 points

16 Posts

Re: Add web reference problem(silverlight 2.0)

 Thank you - it works

bscc
bscc

Member

Member

6 points

5 Posts

Re: Re: Add web reference problem(silverlight 2.0)

Its not working for me ........ following is the exception for..

 

An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code Additional information: [UnexpectedHttpResponseCode]Arguments:Not Found

Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.2&File=System.ServiceModel.dll&Key=UnexpectedHttpResponseCode

 

Kostja
Kostja

Member

Member

38 points

16 Posts

Re: Re: Add web reference problem(silverlight 2.0)

Please show your code

wireplay
wireplay

Member

Member

44 points

20 Posts

Re: Re: Re: Add web reference problem(silverlight 2.0)

I continually have the Arguments Not Found error and I have been working on it all day to no avail. Nothing seems to have an impact. i even built an application completely from scratch, all localhost, all defaults, and the same thing happens.

I am on IE7 and using VS2008 with Cassini for testing.

Web service call:

ServiceReference1.Service1SoapClient soap = new SilverlightApplication3.ServiceReference1.Service1SoapClient();soap.HelloWorldCompleted += new EventHandler<SilverlightApplication3.ServiceReference1.HelloWorldCompletedEventArgs>(soap_HelloWorldCompleted);

soap.HelloWorldAsync();

Web services are the default ASP.NET web services with Hello World.

That is the whole program. I am stumped. It sure seems like i am hitting a configuration issue somewhere.

wireplay
wireplay

Member

Member

44 points

20 Posts

Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

Ok, I pulled this completely out of Cassini and it worked. It didn't work when I tried it on 2 separate machines and I ran into the same error. I am going to put as much detail of this error here so it gets ht by the search engines and may help others.

Also, adding in a clientaccesspolicy.xml file into localhost route had no impact. However, I didn't investigate in detail how Cassini operates so I probably placed it in the wrong location. 

Basically, publish both the services website and the Silverlight website to IIS under localhost.

 

'e.Result' threw an exception of type 'System.Reflection.TargetInvocationException'

{System.ServiceModel.ProtocolException: [UnexpectedHttpResponseCode]
Arguments:Not Found
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.2&File=System.ServiceModel.dll&Key=UnexpectedHttpResponseCode
   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 SilverlightApplication3.ServiceReference1.Service1SoapClient.Service1SoapClientChannel.EndHelloWorld(IAsyncResult result)
   at SilverlightApplication3.ServiceReference1.Service1SoapClient.SilverlightApplication3.ServiceReference1.Service1Soap.EndHelloWorld(IAsyncResult result)
   at SilverlightApplication3.ServiceReference1.Service1SoapClient.EndHelloWorld(IAsyncResult result)
   at SilverlightApplication3.ServiceReference1.Service1SoapClient.OnEndHelloWorld(IAsyncResult result)
   at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}

{System.ServiceModel.ProtocolException: [UnexpectedHttpResponseCode]
Arguments:Not Found
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.2&File=System.ServiceModel.dll&Key=UnexpectedHttpResponseCode
   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 SilverlightApplication3.ServiceReference1.Service1SoapClient.Service1SoapClientChannel.EndHelloWorld(IAsyncResult result)
   at SilverlightApplication3.ServiceReference1.Service1SoapClient.SilverlightApplication3.ServiceReference1.Service1Soap.EndHelloWorld(IAsyncResult result)
   at SilverlightApplication3.ServiceReference1.Service1SoapClient.EndHelloWorld(IAsyncResult result)
   at SilverlightApplication3.ServiceReference1.Service1SoapClient.OnEndHelloWorld(IAsyncResult result)
   at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}

 

Ajay Gaikwad
Ajay Gai...

Member

Member

44 points

30 Posts

Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

Hi All,

I am still facing the same error even though i had use clientpolicy xml file and publish the website

any idea

Thanks & warm Regards
Ajay Gaikwad|Software Engineer
Accenture|Delivery Centers for Technology in India
Godrej&BoyceComplex,LBSMarg ,Vikroli(West)
ajay.gaikwad@accenture.com

lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

Hi,

i tried using add service reference instead of add web reference.

after i added that web service, in intellicence, it should show me the list of webmethods. its actually showing the methods but with "async " postfix.

is  it because these web methods are talking to backend data base? because this is only the case with methods returning some value, other void methods are perfectly working!!!

needed help immedtley.

Thanks,

Lakshmi

lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Add web reference problem(silverlight 2.0)

hi, i have created a silver light UI.

There is a login page, which authenticates the user using a webmethod

Authenticate(uname, pwd); which returs "usercontext" data object.but after i refered the webservice which contains this method, it just shows void as return type. not usercontext. why is it happening?

 

 

Kostja
Kostja

Member

Member

38 points

16 Posts

Re: Re: Add web reference problem(silverlight 2.0)

Could you show your code?

lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Add web reference problem(silverlight 2.0)

Hey thanks for the quick reply.. it was least expected.. actually :) 

 the code is below:

 

public
Page()

{

InitializeComponent();

}

private void UserControl_Loaded(object sender, RoutedEventArgs e)

{

 

rotateEllipse1.Begin();

rotateEllipse1.Stop();

 

rotateEllipse2.Begin();

rotateEllipse2.Stop();

 

rotateEllipse3.Begin();

rotateEllipse3.Stop();

 

rotateEllipse4.Begin();

rotateEllipse4.Stop();

 

}

public void validateUser(object sender, RoutedEventArgs e)

{

RES_ServiceSoapClient service = new RES_ServiceSoapClient();UserContext userContextData = new UserContext();

userContextData = service.AuthenticateAsync(user.Text, password.Text);

string role = GetPrimaryRole(userContextData);

if (role.ToUpper() == "HR")

{

TransitionBase transition = new FadeTransition();NavigationHelper.Navigate(transition, new SearchPage());

}

 

Here the method 'Authenticate' takes two parameters username, and password,and it is supposed to return "usercontext" which is a Dataobject.

but the problems i am facing here is,

1. in the intellicense i'm not getting 'Authenticate", but 'AuthenticateAsync" instead.

2.and its showing return type of the method as void(it should show "usercontext" instead.)

 

 

 

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Re: Add web reference problem(silverlight 2.0)

 Hello, you can't use "Authenticate" directly. Everything in Silverlight are in async-mode. Not sync-mode.

You have to use async-mode like below.

For example:

{

WebServiceProxy.ProductManagerSoapClient productMgrSoapClient = new SL2WebSrv.WebServiceProxy.ProductManagerSoapClient();

productMgrSoapClient.RetrieveProductsAsync();
productMgrSoapClient.RetrieveProductsCompleted +=
new EventHandler<SL2WebSrv.WebServiceProxy.RetrieveProductsCompletedEventArgs>(productMgrSoapClient_RetrieveProductsCompleted);

}

void productMgrSoapClient_RetrieveProductsCompleted(object sender, SL2WebSrv.WebServiceProxy.RetrieveProductsCompletedEventArgs e) {
if (e.Error == null)
   displayData(e.Result);
}
 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


Kostja
Kostja

Member

Member

38 points

16 Posts

Re: Re: Add web reference problem(silverlight 2.0)

Try to use code bellow

 It needs to replace {Service namespace }

private RES_ServiceSoapClient service;

public Page()
{
      InitializeComponent();
      service =
new RES_ServiceSoapClient();
      service.AuthenticateCompleted += new EventHandler<{Service namespace }.AuthenticateCompletedEventArgs>(Service_AuthenticateCompleted);

private void Service_AuthenticateCompleted(object sender, {Service namespace }.AuthenticateCompletedEventArgs e)
{

    if(null == e.Error)
    {

          RES_ServiceSoapClient UserContext userContextData = new UserContext();
          userContextData = e.Result;        

          string role = GetPrimaryRole(userContextData);

          if (role.ToUpper() == "HR")

          {

               TransitionBase transition = new FadeTransition();NavigationHelper.Navigate(transition, new SearchPage());

          }
}

 

public void validateUser(object sender, RoutedEventArgs e)

{
    service.AuthenticateAsync(user.Text, password.Text);
}

 

Smile 

lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Re: Add web reference problem(silverlight 2.0)

Heyyyy, ! its built successfully with out any error, thanks a lot... :)

Kostja
Kostja

Member

Member

38 points

16 Posts

Re: Re: Re: Add web reference problem(silverlight 2.0)

You are welcome - Please,Mark as Answer

lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

m sorry to ask a stupid doubt, but how to mark it as an answer, i cudnt find that option anywhere!

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

lakshmi krishna:
m sorry to ask a stupid doubt, but how to mark it as an answer, i cudnt find that option anywhere!
 

No. You can't. Only the original poster can mark it as an answer.  I'm not sure why the team of this forum uses that way.....

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Add web reference problem(silverlight 2.0)

Hi,  

i am able to build the solution, but once the user name n password is entered, its giving the below error. 

An exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll but was not handled in user code

Additional information: [CrossDomainError]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.2&File=System.ServiceModel.dll&Key=CrossDomainError

(PLS. Do let me know how to mark a post as answered !! )

lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

hey even u have written - ( If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

could anyone please tell me how do i "mark a post as answer" ???, is there a hyper link or button by name "mark as answer" ?

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

lakshmi krishna:
hey even u have written - ( If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)
 

It's my signature, man. :)

As I said in my previous thread, only original poster can mark it as an answer.. So, it won't be possible for you to do.

 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

oops! ok... i got it :)

lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

Hi, 

i am getting this error , i have been trying to fix this from many days.

An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code

Additional information: The remote server returned an unexpected response: (404) Not Found.

after i edited the manifest, i am able to view the exception in detail!. as shown below. even after including clientaccesspolicy.xml and crossdomain.xml files.

An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code

Additional information: The remote server returned an unexpected response: (404) Not Found.

could anyone tell me the solution for this


 

Ajay Gaikwad
Ajay Gai...

Member

Member

44 points

30 Posts

Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

Hi  lakshmi

Are you trying to use you WCF service using IIS.if so then please add .SVC extension from confirgution option of property of your virtual directory.Error may occur due to access problem. your silverlight desktop apll will not understand where the service is avaiable. can you please check the address of your service in webconf file in web app and service confirgution file it should be same. please let me know if you need more clarifcation on same.

 

Thanks & warm Regards
Ajay Gaikwad|Software Engineer
Accenture|Delivery Centers for Technology in India
Godrej&BoyceComplex,LBSMarg ,Vikroli(West)
ajay.gaikwad@accenture.com

lakshmi krishna
lakshmi ...

Member

Member

42 points

21 Posts

Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

Hi Ajay,

Thanks. Actually i found the solution.

I am using a simple asmx service. I created one more service in the same domain as of the Application to access the cross domain service,now its workin perfectly..

deepikaFO
deepikaFO

Member

Member

14 points

7 Posts

Re: Add web reference problem(silverlight 2.0)

Hi,

iam getting the same error wha tu mentioned in this thread

"An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code".

i read the answer what u ahve given but iam not able to understand properly.

How to add "clientaccesspolicy.xml " ,and where to add???????

i have one silverlightApplication,one webservice.

iam calling webservice in silverlgiht applciation by using service reference.

and i have written the code in xaml.cs to call the web service.

iam not understanding what is the root ?where to add the "clientaccesspolicy.xml"?

iam calling webservice in the silverlgiht application ,so silverlgiht application becames the host of the webservice,Right????????

so that i added this "clientaccesspolicy.xml" in the silverlgiht applciation.

plese reply me ASAP.

 

Thanks & Regards

Deepika

 

Jim Mangaly
Jim Mangaly

Contributor

Contributor

2610 points

380 Posts

Re: Add web reference problem(silverlight 2.0)

I suppose your solution has 3 projects - the Silverlight application, the web app that hosts the Silverlight project and the Web service project, right? Your policy file should be added to the root of the third project. You can copy it next to the .svc file.

However, if you are only consuming an external service over which you have no control over, you can only hope that the provider of the service has the policy file in place.

Cross domain access without the policy file is forbidden in Silverlight to avoid cross site forgery. Read this MSDN article and three part article by Karen Corby starting here.

Hope this helps,
Jim (http://jimmangaly.blogspot.com/)

Please MARK the replies as answers if they answered your question

http://www.identitymine.com/

amurawat@hotmail.com
amurawat...

Member

Member

8 points

6 Posts

Re: Add web reference problem(silverlight 2.0)

Please can u tell me how to add a refernce to the MSn Search lnk in a silverlight application

I want to add a refernce to the following link: http://soap.search.msn.com/webservices.asmx?wsdl 

its very urgent.

simbuaarumugam
simbuaar...

Participant

Participant

1172 points

405 Posts

Re: Re: Add web reference problem(silverlight 2.0)

 Hi amur

You just download the file what you want to add the reference in to your project like (.dll) files . and the open your project in your project silvelright references is there .Just right click on that give add references .then click the Browse button and add the referece where you save the download file 

SimbuAarumugam India
http://simbusoftwareengineer.blogspot.com
(Mark As Answer If its Satisfy your needs)

simbuaarumugam
simbuaar...

Participant

Participant

1172 points

405 Posts

Re: Re: Re: Re: Re: Re: Add web reference problem(silverlight 2.0)

 hi lakshmi

Did you use LINQ in your project .. please update the service reference in your project or delete and re add your service references .. this is a problem for generating the error The remote server returned an unexpected response: (404) Not Found.   Check it correctly 

SimbuAarumugam India
http://simbusoftwareengineer.blogspot.com
(Mark As Answer If its Satisfy your needs)

kwells5750
kwells5750

Member

Member

2 points

1 Posts

Re: Re: Add web reference problem(silverlight 2.0)

 Thank you Kostja.  Your code is very clear and helpful to newbee like me.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities