Generate Proxy VB Class from WSDL for Windows Phone 8.1 - vb.net

I just finished working on the Android port of the iOS App that I have and now the client also wants to have a Windows Phone version just so they can have an App for all three markets and right now I'm not sure how to consume the Web Services as the "Add Service Reference" option has been removed for Windows Phone 8.1 apps. I don't know if there's any online alternatives that create a proxy class like what the "Add Service Reference" did, I tried using the Svcutil.exe option to generate my own proxy but when I imported the file it was littered with errors and undefined types that aren't available for Windows Phone projects. Other than the proxy route I was reading that HttpClient should work, but so far I haven't been able to have much success with it (below is what I tried but I keep getting an error, and this is a more simple service, where some of the other services are more complex). For the Android and iOS projects I was able to find some online generators that created the proxy classes from the WSDL files and I've been trying to see if there's something similar for WP8.1 but so far I've been unsuccessful.
Public Shared Async Function GetSession() As Task
Dim values As New List(Of KeyValuePair(Of String, String)) From {
New KeyValuePair(Of String, String)("RepLogin", "username"),
New KeyValuePair(Of String, String)("RepPass", "password")}
Dim httpClient As New HttpClient(New HttpClientHandler())
Dim requestString As String = mobileAddress + "?op=VerifyRep"
Dim response As HttpResponseMessage = Await httpClient.PostAsync(requestString, New FormUrlEncodedContent(values))
Debug.WriteLine(response)
Dim responseString = Await response.Content.ReadAsStringAsync()
Debug.WriteLine("response string contains: " + responseString)
End Function
And before anyone suggests that the Web Service should be updated from SOAP to a WCF or something else that really isn't a solution in this scenario since the client already has several Web Applications and now two mobile apps (the iOS and Android ones) that all use this Service without any issues and it's going to be hard to convince them that everything needs to be reworked just for the sake of getting a Windows Phone app up and running

Okay, so I figured out my problem was that when I created the project I just chose the Windows Phone template, which uses the Windows Runtime in order to share code with a Windows 8.1 App as well (which I still don't know how they would share if you can't consume a web service but that's not for here). I created a new project using the Windows Phone Silverlight template and now I can add a Service Reference as normal, and since I'm not planning on creating a Windows App that will share code with the Windows Phone app this is the way to go. Thanks anyways.

Related

Web Api documentation with swashbuckle

We are currently trying to start writing WebApi services for our products switching from traditional WCF SOAP based services. The challenge we have got is how to provide the api documentation. I came across the SwaggerUi/swash buckle.
One limitation we have is we do not want to host the WebApi services in IIS but in a Windows Service. I am new to Web Api so I might be doing things the wrong way.
So for testing, I am hosting the web api in a console application. I can use the HttpClient to invoke the Get method on the Web Api but I can't access the same if I type the url in a web browser (is this normal for self hosted web api?).
So I installed the Swashbuckle.core nuget package and included the following code in the Startup class (Owin selfhosted).
var config = new HttpConfiguration();
config
.EnableSwagger(c =>
{
c.IncludeXmlComments(GetXmlCommentsPath());
c.SingleApiVersion("v1", "WebApi");
c.ResolveConflictingActions(x => x.First());
})
.EnableSwaggerUi();
private static string GetXmlCommentsPath()
{
var path = $#"{AppDomain.CurrentDomain.BaseDirectory}\WebApiHost.XML";
return path;
}
When I browse to the following location
http://localhost:5000/swagger/ui/index
I get "page cannot be displayed" in IE. Similar for chrome.
Is there anything special that needs to be done when hosting a WebApi in a console/windows service application to get the documentation automatically?
(I have enabled Xml documentation for the project)
I have now attached a test project. Please follow the link below:
Test project
Regards,
Nas
Your problem is not with Swashbuckle, which is configured correctly. Instead it is with the fact that your OWin web app has closed by the time the browser navigates to the swagger URI. Your using statement means that the web app is shut down at the end of it - well before Chrome has opened and navigated to the swagger path. You need to ensure the web app is still running - then your path will be valid (although in your source code you have different ports 9000 and 5000 in your url variables).

Wcf Services in Ektron

I am working with WCF Services in Ektron(rrot/Workarea/Services).
When i am trying to consume the ContentService.svc service in a client using the following code,
ContentManagerClient cClient = new ContentManagerClient();
UpdatedContentService.ContentData data = new UpdatedContentService.ContentData();
data.m_strTitle = "test";
data.m_strHtml = "test";
data.m_intFolderId = 72;
data.m_intUserId = 1;
cClient.Add(data);
I am getting the following error ' The current user does not have permission to carry out this request'.
How can i authenticate an ektron user to perform this action from a client?
The answer you received on the ektron dev forums was a good one. (prior discussion for anyone with the same problem: http://developer.ektron.com/forums/?v=t&t=1280)
You will need to use the Auth service, not the content service. this can be done using the following steps:
Create a proxy object for the web service:
Run .Net tool wsdl.exe against your webservice address, e.g. http://localhost:/Workarea/webservices/AuthService.asmx
Compile into DLL by running “csc /t:library AuthenticationService.cs”:
Add the DLL as a reference to your DLL or console app
Copy the DLL to a Lib folder in your project
Add the DLL as a reference to your DLL or console app
Copy the DLL to a Lib folder in your project
Right click “Add reference” and browse to your created proxy DLL.
Add System.Web.Services as a reference to your DLL or console app
Call the proxy code from your app:
AuthenticationService auth = new AuthenticationService();
IAsyncResult response = auth.BeginisValidUser(username, password, etc...);
a working code example of this can be found at:
http://developer.ektron.com/Templates/CodeLibraryDetail.aspx?id=1036&blogid=116
This example was adapted from the VooDoo engineering example of pulling in the content service:
http://ektroneering.blogspot.com/2011/01/accessing-ektron-from-dll-or-console.html

ASP.NET WebAPI fails from MVC4 controller

I'm new to ASP.NET Web API and I'm struggling with a very strange problem.
I have some code which calls a RESTful service and it executes fine from a console project, but I can't get it to run from an MVC4 project running under .NET 4.0
The code to call the service is very simple:
internal string Test()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://testserver");
var task = client.GetAsync("/someUri")
var response = task.Result;
response.EnsureSuccessStatusCode();
return response.Content.ReadAsStringAsync().Result;
}
}
As mentioned, called from a console project it works as expected and I get a response in milliseconds, however if I call the method from an action in my MVC4 controller after a few seconds I get a message stating that:
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to repond".
Weirdly, when debugging the MVC4 version, the task status always shows as WaitingForActivation.
Running fiddler doesn't show any request being made from the MVC4 version, but again does for the Console version.
After a fairly serious bit of googling I can't find anyone else who seems to have had this problem, so I'm guessing that I've fundamentally misunderstood something, but at the moment I'm not sure what!
Updated 16:55 BST, 11/09/2012
To make things even weirder, I've just created a new MVC4 site and I can call the method without any problems! I'm now trying to compare the sites, however one was an existing site that was upgraded to MVC4 and the other is a new blank site, so spotting the relevant difference could be tricky.
Updated 16:44 BST, 14/09/2012
This is now looking like some infrastructure / networking issue.
I upgraded the project to VS2012 with .NET 4.5 so that I could use async/await to try the suggested implementations to avoid a deadlock. This didn't change anything so I went back to square 1.
I created a new solution with a new MVC4 project, a new services library and a unit test project to run the service library outside of MVC.
In the service library I created one method to call a public "what's my IP" service, and another to call a company service that's exposed publicly but only responds properly to company IP addresses.
For some background, I connect in to the company LAN via a VPN.
When disconnected from the VPN, in both unit tests and MVC, the IP service responds HTTP 200, the company service responds HTTP 404 as expected.
When connected to the VPN, unit tests both respond HTTP 200, MVC both timeout.
Next I ran MS Soap Tool locally and used that to proxy calls to the company services. All calls (whether from unit tests or MVC) show a request and response, but the unit test registers the response whilst the MVC controller does not.
My only other thought is that it could be something to do with the size of the reply? All the "successes" have very small replies other than the unit test calling the company service?
The Microsoft recommended way to upgrade an MVC3 to MVC4 site is to start with a completely new MVC4 site a migrate your views, controllers & code over. So I think that your upgrade steps may be part of your issue, since you were able to get it to work in the new MVC4 site you created. If you need to manually upgrade your existing site, I would follow the steps outlined in Upgrading ASP.NET MVC 3 Project to ASP.NET MVC 4

Consuming web service from console app

We have a web app that contains web methods. I want to invoke one of those methods from a console app. I am new at this but I wrote a console app, added a service reference and tried to code invoking it.
If my web method is called "Transmit", I expected to see Transmit in the namespace I specified but instead I see "TransmitRequest", "TranmsitRequestBody", "TransmitResponse" and "TransmitResponseBody".
What are these things?
Have I done something wrong?
How do I invoke the web method in the web app from the console app?
Thank you for all help to this newbie. I am using VB.net 2008.
If you expand the ServiceReference Folder in solutionExplorer, double click on your service and it should open the object explorer. Now you will see the class (the one without the I infront). In your code you will then instantiate a new variable with the [ServiceReferenceName].[ClassName] i.e.
Dim svc as new ServiceReference1.MyWebService();
svc.Transmit();

Web Service missing methods when called from Silverlight

I created WCF web service, deployed it, and debugged it. I wrote a console app, referenced the web service, and everything works.
Now, I'm attempting to consume the web service in a silverlight 3 application. I added the following code to a click event.
TagServiceClient client = new TagServiceClient();
Tag[] tags = client.GetTags();
client.Close();
VS is telling me it can't find the GetTags() and Close() methods. But VS has no problem with these methods in the console app.
I added a using statement for the service reference to the top of my file.
I placed a clientaccesspolicy.xml file in the root domain and in the folder containing the web service. Doesn't seem to change anything regardless where it is.
What's going on? Any suggestions? This is my first time consuming a web service in Silverlight so I may just be missing something.
You will need to generate a new client proxy to use in the Silverlight app - IOW, from the Silverlight app, add a new service reference, and point it to the service.
You will then see that things are a little different - you will find that there are async methods in the proxy, not the synchronous ones you will have seen in the proxy generated for the console app. So in the silverlight app, your code will end up looking something like this:
client.GetTagsCompleted += [my event handler];
client.GetTagsAsync();
and in your event handler:
if (e.Error == null)
if (!e.Cancelled)
List<Tag> tags = new List<Tag>(e.result);
When you add a the service reference to the silverlight app, make sure you have a poke around the advanced settings, because you can change what sort of collection the items are returned in, etc (the default return collection is an ObservableCollection<T>).
If you want to avoid this sort of thing (different proxies for different apps or modules), then consider using svcutil to generate your proxy instead of allowing VS to do it (VS doesn't use svcutil).