I'm new to silverlight, I want to add web reference to silverlight application is that possable???
I can only add service reference to the SilverightApplication but i want to add web reference.
I can add web reference to the SilverightApplication.Web, can i use it from SilverightApplication??
I aslo can add service reference to the SilverightApplication but functions of service reference has no return value so i cant recieve the data, here is the code
Service1SoapClient c = new Service1SoapClient();
ServiceReference1.Service1SoapClient a = new ServiceReference1.Service1SoapClient();
a.returnStr_19_9Async("");
the function returnStr_19_9Async("") has no return value can any one please tell me what is teh wrong??
Can you please tell me how, please explain..
Thanks.
The problem you may be striking is that WCF calls are all done asynchronously in Silverlight. This means when you call your initial service function (let's call it GetMyClient(int clientId) ), the proxy that you have generated will have a function called GetMyClientAsync(), and it will also have an event called GetMyClientCompleted which you must subscribe to:
myProxy.GetMyClientCompleted += new EventHandler<GetMyClientCompletedEventArgs>(MyProxy_GetMyClientCompleted);
that event handler will look something like this:
private void MyProxy_GetMyClientCompleted(object sender, GetMyClientCompletedEventArgs e)
{
//e.Result will have your returned values
}
This is just a very brief overview that gives you enough to get started. You could also read more here: Silverlight.net | Data & Networking | Network Services (Soap, REST and More)
Related
I am bit curious about one thing which has happen while trying to understand the concept of Service References and Web Service References.
What I did is?
In my project I have added a web service as a Service Reference and trying to get my script run through the use of client.
But while getting result it is throwing an exception as in the following image:
I have tried to trace out the cause but not able to get the proper answer for that.
I have following code for the resultant object.
[
ComVisible(false),
Serializable,
SoapTypeAttribute("RecordList", "http://www.someadd.com/dev/ns/SOF/2.0"),
XmlType(TypeName="RecordList", Namespace="http://www.someadd.com/dev/ns/SOF/2.0")
]
public class MyRecordListWrapper
{
private IxRecordList recordList = null;
private const string XMLW3CSchema = "http://www.w3.org/2001/XMLSchema";
[SoapElement("Headers")]
public Header[] Headers = null;
[SoapElement("Records")]
public Record[] Records = null;
// some methods to work on intialization
public SmRecordListWrapper(ref IxRecordList p_RecordList)
{
recordList = p_RecordList;// record list initialization
Headers = CreateWrapperHeaders(); // will return header class object
Records = CreateWrapperRecords(); // will return record object
}
}
Can anyone tell me why this error is showing for me?
While adding reference as a Web Service Reference
when I add the same reference as a web reference that time the program is not showing any error and runs successfully?
So can anyone tell me what is the difference in working with the same code using service reference and web service reference?
and Which is a correct way to ass references?
Hope I will get some more described answers to make the things easy to understand.
Thanks in advance.
Adding a web reference, visual studio uses xsd.exe to generate the classes from the service metadata. This uses XmlSerializer under the hood.
Adding a service reference, visual studio uses svcutil.exe to generate the classes from the metadata. This uses DataContractSerializer under the hood.
Two separate tools, two outcomes. For general information, DataContractSerializer is a lot less forgiving when it comes to generating classes from metadata.
I have save the wsdl into my local computer, so I have create a new project with visual studio (c#) then I have import this file. So I have the WSDL into my project and I have PianoResidentialService under "Service Refereces" folder.
Now I want to try to call a web service. But I don't know how do this.
I have try this code but now works.
public MainWindow()
{
InitializeComponent();
PianoAssistenzialeResidenzialeService.getPianoAssistenziale ws_PA = new PianoAssistenzialeResidenzialeService.getPianoAssistenziale();
}
If I try to get Inspect ws_PA, all field is null.
You probably need to specify the endpoint:
ws_PA.URL = "http://some.server.com/endpoint/";
Then, you should call a method which is generated for the operation you want to call. (Remember that a webservice can have multiple operations.)
var result = ws_PA.Operation(parameters);
You might want to share the WSDL with us and tell us in more detail what you want to achieve.
I have a rather outdated assembly that I'm using to communicate via SOAP with software my company writes. As it stands right now, getting the assembly updated is not an option, so please don't suggest it.
In previous iterations the normal method of communication was done utilizing the MS Soap Toolkit 3.0 (MSSOAPLIB30). You would call the login() method of the assembly and it would return an instance derived from IHeaderHandler that you would then assign to the instance of the soap client. Please refer here for more information on how this worked.
Well, I would like to use a more updated approach for communication with this web service. Thus far I have been able to successfully reference the web service with wcf, however I'm running into issues figuring out how to bridge the IHeaderHandler instance to something that the wcf proxy can comprehend. In other words, I'm trying to bridge two generations of technologies together. I've verified that using the method mentioned in the link above does actually work. Now it's just a matter of figuring out how to make this instance of IHeaderHandler useful.
Here is some example code for the old approach:
string strBasicWsdlUrl = "http://" + _strDeviceName + "/MetasysIII/WS/TimeManagement/TimeService.asmx";
object[] Parameters1 = new object[] { strBasicWsdlUrl, "", "", "" };
bool[] Parameters2 = new bool[] { true, true, true, true };
TSClient = Activator.CreateInstance(Type.GetTypeFromProgID("MSSOAP.SoapClient30"));
NewLateBinding.LateGet(TSClient, null, "MSSoapInit", Parameters1, null, null, Parameters2);
Parameters1 = new object[] { NewLateBinding.LateGet(JCISecurity, null, "HeaderHandler", new object[0], null, null, null) };
NewLateBinding.LateSet(TSClient, null, "HeaderHandler", Parameters1, null, null);
As you can see, a new instance of the soap client is initialized with the wsdl file and then the HeaderHandler attribute from the JCISecurity instance (which is the aforementioned assembly I'm using to authenticate with the software) which is derived from IHeaderHandler is passed to the HeaderHandler of the soap client. This process then ensures that all future requests from the soap client have this header attached.
It's also important to note that the proxy class generated from WCF for my web service has two interesting parameters attached to all web methods: EncryptedCertificate and LoginResult. I'm assuming these values will exist in the IHeaderHandler instance as the original documentation of the service does not reference these two parameters. However, I cannot verify this is the case because I've yet to be able to figure out how to access the content embedded in the IHeaderHandler instance.
As it stands, I see two possible solutions at this point: Figure out a way to make the WCF proxy class directly use the IHeaderHandler instance being generated with the assembly or figure out a way to extract the necessary information from the IHeaderHandler instance and use Message Inspectors to manually attach the details to the headers.
WCF is very extensible. One of those extension points is Message Inspectors:
A message inspector is an extensibility object that can be used in the service model's client runtime and dispatch runtime programmatically or through configuration and that can inspect and alter messages after they are received or before they are sent.
See also WCF Extensibility Samples and Extending WCF.
I have a WCF method which have a nested List parameter, like this
public void Method(List<class1> class1Obj, List<List<SomeClass>> someClassObj)
{
// CODE
}
After setting service reference I get this in my client reference method through which I can call my WCF method
public void Method(class1[] class1Obj, SomeClass[][] someClassObj)
{
base.Channel.Method(class1Obj, someClassObj);
}
Now to call this method from my code I can do this
void myServiceCaller()
{
List<class1> class1Obj = new List<class1>();
// Add items to class1Obj
List<List<SomeClass>> someClassObj = List<List<SomeClass>>();
// Add items to someClassObj
ServiceRef.myServiceClient service = new ServiceRef.myServiceClient();
service.Method(
class1Obj.ToArray(), // This one is fine
someClassObj.ToArray() // This gives me compile time error
);
}
How can I resolve this issue to convert List<List<SomeClass>> to SomeClass[][] ?
When you add your Service Reference and the dialog pops up you can click the Advanced... button in the lower left and change the Collection type drop-down from System.Array to System.Collection.GenericList this will then change the proxy that is created and use List<...> instead of [...] when collections are used.
In addition, if you have already added your Service Reference you can right-click on the Service Reference within the Solution tree and click Configure Service Reference... from the context-menu. This will show the same "Advanced" dialog mentioned above.
I have Visual Studio 2010, using c# and I want to add this web service to my site:
http://www.webservicex.net/geoipservice.asmx
I have added the web reference as "getip"
and my code is
protected void Page_Load(object sender, EventArgs e)
{
getip.GeoIPService yourip = new getip.GeoIPService();
Label4.Text = yourip.GetGeoIPContext().ToString();
}
But when the site loads the only thing appearing in my label is "getip.GeoIP "
First of all, you shouldn't use Web References anymore. Use "Add Service Reference" instead. Web References use the old "ASMX" technology. All new work should use the WCF technology, even if you're calling a .asmx web service.
Second, the service has returned you an object of the type getip.GeoIP. There's no doubt properties in that object. Try
getip.GeoIP geo = yourip.GetGeoIPContext();
And then type "geo." and see what Intellisense tells you is in there. Alternatively, stop after that line in the debugger, and look inside to see what you want to put into your label.