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.
Related
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 program that utilize a web service. When this web service is tested on its own (run on ie AS .asmx) runs fine but when tried to be called from inside the web form it produces the following error:
Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.
The web servce is:
public Check1 () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public void check2(string destination)
{
Server.Transfer(destination);
}
}
And the web form from which is called is:
protected void Button1_Click1(object sender, EventArgs e)
{
localhost.Check1 new2 = new localhost.Check1();
new2.check2("Ipal_apoth_page.aspx");
}
A web service is intended to be a data interface, not a web page server, which is why XML is expected. Web service protocols use XML format for their communications, e.g. WSDL or SOAP. The .aspx page you attempt to transfer the processing to will return HTML.
It may be that when you tried it in a browser, the browser was permissive enough to interpret the repsonse from the web service in the way you wanted even though that is not how it is meant to be used.
A better thing to practise with would be something simple like adding two numbers.
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)
I'm working on a C# library class which is being consumed by an ASP.NET 4.0 Web Forms application. In my class, I'm trying to access the HttpRequest.Application object as described here:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx
This documentation says it is in the System.Web namespace but even when I add a reference in my library project, it is still not available to me.
The only way I can get to the ApplicationPath property is by using:
HttpContext.Current.Request.ApplicationPath;
What's going on?
ApplicationPath is not a static property on HttpRequest, which is why you have to access it using the instance HttpContext.Current.Request. If you don't want to use HttpContext.Current.Request you could always pass the HttpRequest object in to your class library from your ASP.NET web forms.
For example (from your Page_Load):
protected void Page_Load(object sender, EventArgs e)
{
var myClass = new MyClass();
myClass.MyMethod(this.Request);
}
After my previous question HERE, I found the solution (well, part of it).
Here's the code for Java part:
#WebService
public class MyWebService
{
#WebMethod
public String myMethod()
{
return "Hello World";
}
#WebMethod
public int Add(#WebParam(name="a") int a,
#WebParam(name="b") int b)
{
return a + b;
}
public static void main(String[] args)
{
String address = "http://127.0.0.1:8023/_WebServiceDemo";
Endpoint.publish(address, new MyWebService());
System.out.println("Listening: " + address);
}
}
And Here is the Silverlight part:
private void SearchResultList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MyWebServiceClient proxy = new MyWebServiceClient();
proxy.AddCompleted += proxy_AddCompleted;
proxy.AddAsync(2, 3);
}
void proxy_AddCompleted(object sender, AddCompletedEventArgs e)
{
txtSearch.Text = e.Result.ToString();
}
But when I run this, e.Result throws an exception.
What am I missing/ How should I solve it?
Note that this code runs perfectly in C# Console application (when it's not async). But when I run the async code, it doesn't work.
Thanks in advance.
I guess you are getting a System.ServiceModel.CommunicationException when trying to access the Java Webservice from Silverlight.
There is nothing basically wrong with your code, and it should also work with async calls in C# Console App.
The main problem is that Silverlight (as a browser plugin) enforces some security restrictions that prevent a Silverlight Application to talk to another server than the one loaded from (defined by server name and port) without further configuration. This behaviour can be configured as described here (also search for "silverlight cross-domain calls" or "silverlight cross domain policy").
This restrictions (normally) do not apply to desktop or console applications so they'll work fine with the same web service.
To make your code work you need to host the Silverlight Application inside the same "project" / website than your webservice (so I suppose, the self-hosting webservice won't work and you need to switch to Java web project where the webservice is to be hosted). As the Silverlight Application basically consists of an enclosing HTML file plus the referenced binaries, you can host it on any server, e.g. Apache Tomcat.
Hope this helps.