How to consume credential based webservice (asmx) in Asp.net Core web application? - web-services

I am facing issue while adding asmx service in .NetCore Console application. I am using WCF Connected Service extension as add web reference is not available. So,I followed the same steps which was suggested in following link
https://blogs.msdn.microsoft.com/webdev/2016/06/26/wcf-connected-service-for-net-core-1-0-0-and-asp-net-core-1-0-0-is-now-available/
After completing all step it provided auto-generated reference class which contains all method as async method. My asmx service required username and password authentication for each method and we pass credential as first parameter of any method.
for example, using web reference my method looks like GetData(Credential credential) but here auto generated class shows this method like
GetDataAsync() so I used the below mention code to pass the credentials before calling my web service method
client.ClientCredentials.UserName.UserName = "myusername";
client.ClientCredentials.UserName.Password = "mypassword";
It's giving me Not Authorized error, after putting the breakpoints I found that credential was not getting at asmx service.
Please suggest some solution.

Previous Approach I Took:
I ran into a similar issue. I have an MVC Core web application (targeting .NET Framework 4.6.1) and was not able to add a Web Reference the way I used to be able to within previous (non-Core) applications. I was not able to get Connected Services to add a reference to an asmx and allow for the passing of credentials.
To work around this, I created an additional project (a class project also targeting .NET Framework 4.6.1). From there I was able to add a Web Reference the way one could in the past. Within this project I created a class with a publicly accessible method that calls the asmx service.
Then, within my MVC Core project, I set a reference to this additional project and am able to call the public method on the other project.
Latest and Best Approach I Have Found:
I fully updated VS 2017 as well as going to this site to get the latest WCF Connected Services extension (https://marketplace.visualstudio.com/items?itemName=WCFCORETEAM.VisualStudioWCFConnectedService).
The AuthorizationSoapHeader was easy to access and set.
MySoapClient.EndpointConfiguration endpoint = new MySoapClient.EndpointConfiguration();
MySoapClient myService = new MySoapClient(endpoint, myURL);
AuthorizationSoapHeader MyAuthHeader = new AuthorizationSoapHeader();
MyAuthHeader.AppName = FDSServiceAppName;
MyAuthHeader.AppID = Guid.Parse(MyAppID);
Entry[] entries = MyService.GetUsers().Result;

I faced the same problem and i resolved it owning to github issues :
In Reference.cs substitute
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding()
for
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly);
result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic;
This really worked in .net core client app for soap web services

Related

Two method error in .asmx web service

I developed a web service and i write with c#. My web service is an asmx. But in my service i have 2 method. first one is helloworld(),second method is insert_Data. All of them is webmethod. But if i want to write third method , my application give me an error. My application couldn't see any method like insert_Data or helloworld or new method is refresh.
I used to Ado.net entity data model,and can't find anything about this problem.
Thanks

How to handle several marshalling profiles in RestEasy?

I developed a RestFul web services application with RestEasy currently working on Resteasy 2.3.5 and JBoss 4.3.2GA.
I would like to publish chosen attributes to chosen users of my web services.
For instance here is an object User :
User:{id=123, name=Jack, password=MyNameIsJack}
When a web service user with an lambda profile ask for the object Jack my application should return :
{id=123, name=Jack}
When a web service user with an admin profile ask for the object Jack my application should return :
{id=123, name=Jack, password=MyNameIsJack}
Is there a way to do that using RestEasy Framework?
Thx
I tried the solution given by #Blaise Doughan but ObjectGraph override the existing annotation based mapping on my class.
What I wanted is to extend this mapping.
So I chose to do this by extending my annotation mapping with an xml mapping.
According to the tutorial by Blaise, you can do this using MOXy :
extending-jaxb-representing-annotations
Dont forget to write a jaxb.properties file which specify which implementation of JAXB to use : specifying-eclipselink-moxy-as-your-JAXB-implementation
It's working fine for me.
Thx Blaise !

GWT: Expose the service implementation class as web service

Problem scenario is: I am writing a Google Gadget. Data presented in the gadget will come from my deployed GWT app. I am planing to call the web service from Java script to show the required data.
I need to know how I can expose the Service implementation class like GreetingServiceImpl(generated by default as sample in Eclipse GWT project) as web service.
I did tried to to expose the logic using approach suggested here(http://igorshare.wordpress.com/2009/05/20/building-gwt-web-clients-part-2-how-to-expose-rest-full-jax-rs-service-with-jersey-on-tomcat-server/).
But rather than creating the dynamic web project, I created the Google web project in Eclipse. And I am getting the 404 exception.
Any suggestions why I am getting 404 error?
Regards,
Vikram
Check this: Retrieving JSON Data

InfoPath call web service locally

I've created a C# Class Library with common classes I'm going to use in all my forms.
I've signed the assembly and added [assembly: AllowPartiallyTrustedCallers] to AssemblyInfo.cs.
I've created a Web Reference to the List sharepoint service in order to call GetListItems since I didn't manage to call it using InfoPath's DataConnection.
Then I've added a reference to my assembly from a Form Template project from VSTA.
After I publish this form to SharePoint and then open a new form from sharepoint using infopath client the web service call works fine.
But if I try to preview the form locally by running it from VSTA I get a security exception telling me it's can't get System.Net.WebPermission.
Now, I guess it works from the published form because it accesses the same sharepoint server as the one where the form is stored.
My question is whether it's possible to also make it work when I preview it locally? It would make my development cycle much shorter (don't have to publish the form each time).
Thanks,
Michael
I found a workaround which enables me to develop and debug easily. While developing I set the form trust level to Full Trust. Before deploying to Sharepoint I change the trust level back to normal.

Flex4 - Refreshing Auto-Generated Web Service Classses

I am using Flex4 to connect to a SOAP web service. I'm generating the ActionScript classes using the Introspection Wizard in Flash Builder. That all works.
However, the web service is itself under development, so I need to periodically regenerate those AS classes to pick up the new methods or changed method signatures. The only way I've found to do that is to delete the existing classes, and re-run the wizard. HOWEVER, when I do that I also need to give the service a new name, or I see an error saying that the service already exists.
Is there any way to 'refresh' existing web service class definitions WITHOUT having to delete, come up with a new name, and re-create?
Thanks
Got it -- Show View -> Data/Services. You can refresh the service there and choose which methods to generate code for...