WebService RequestSoapContext property not found - c#

I have a asp.net website in visual studio 2013. I added a webservice. I need to send authentication parameter (username and password) as SOAP header. But it cannot find the property RequestSoapContext.
I added using Microsoft.Web.Services3; in my code.
CCWS.Service proxy = new CCWS.Service();
UsernameToken userToken = new UsernameToken("", "", PasswordOption.SendPlainText);
proxy.RequestSoapContext.Security.Tokens.Add(token);
Some forum says to change reference type in reference.cs file. But I cannot find any such file in my solution.
Can anyone please help?

This question is rather old but after searching around, it appears the solution is to hand modify the generated proxy code to inherit from Microsoft.Web.Services3.WebServicesClientProtocol not System.Web.Services.Protocols.SoapHttpClientProtocol.

Generate Code Using WseWsdl3.exe
Locate the WseWsdl3.exe downloaded as part of wse 3.0 and execute the following command:
C:\samples\wse>WseWsdl3.exe C:\samples\wse\us.wsdl /out:c:\samples\wse\myProxyClass.cs /protocol:SOAP /type:webClient
I guess this may help you.

Related

how to add encodingStyle to soap client using c#

the data I send to a web service, gets there with some strange characters.
so the web service developer asked me to add this code to the soap envelope:
soap:encodingStyle=http://www.w3.org/2003/05/soap-encoding
I tried adding this code, but it did not work:
MessageHeader aMessageHeader =
MessageHeader.CreateHeader("encodingStyle", "http://tempuri.org",
"2003/05/soap-encoding");
OperationContext.Current.OutgoingMessageHeaders.Add(aMessageHeader);
how do i add to the soap:envelope a encodingStyle attribute in c#?
I had the same issue as you reported. I found that this was a reported issue in the WCF.
https://github.com/dotnet/wcf/issues/3870
For the fix, I updated the following NuGet packages in my project from version "4.4.*" to "4.7.0"
System.ServiceModel.Duplex
System.ServiceModel.Http
System.ServiceModel.NetTcp
System.ServiceModel.Security
It now includes the "encodingStyle" attribute in the correct location.

Which reference to use in C# - ConvertIdType

I am a C# newbie and trying to use the example in the below link.
https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/bb799791(v%3Dexchg.140)
The problem is, it is asking for a reference and I can't seems to find it under
Microsoft.Exchange.WebServices or any of the sub references under that, eventhough article pointing it to be part of the Exchange webservices.
Error occurs under the below line. It says something about a missing directive.
ConvertIdType request = new ConvertIdType();
Below is my code:
using System,
using Microsoft.Exchange.Webservices;
ConvertIdType request = new ConvertIdType();//error on this line.
ExchangeServiceBinding esb = new ExchangeServiceBinding();// same error on this liine too
exchange = new ExchangeService(ExchangeVersion.Exchange2010_SP1); //this line works fine.
What am I doing wrong here?
Thank you for your answers/pointers
UPDATE:: Thank you all for trying to answer my question. Sorry for not getting back earlier as I seem to have moved from that approach and continued without the requirement of this piece of code. It's been more than a year and I can't remember what was my ultimate goal in this.
In your example you have posted both code for the EWS Managed API library and the EWS WSDL proxy. ConverItType is a class from the WSDL proxy unless you have a need to write code using the WSDL proxy i would suggest you stick to using the EWS Managed API which will make you life a lot easier. Your code for the EWS Managed API should look like
using System,
using Microsoft.Exchange.Webservices.Data;
ExchangeService exchange= new ExchangeService(ExchangeVersion.Exchange2007_SP1);
exchange.Credentials = new WebCredentials("user1#contoso.com", "password ");
exchange.AutodiscoverUrl("user1#contoso.com");;
then whatever you want to do eg if you want to convert and Id then use the sample from https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/gg274397(v%3Dexchg.80)
According to the documentation, the type ConvertIdType should be under the namespace ExchangeWebServices and not under Microsoft.Exchange.WebServices.
Hope it helps!

Magento Go C# requesting API fails to initialize

I am trying to connect to Magento API using C#. I am using Magento Go service and from what I've read I am able to use their API - I hope I am not wrong here. So here is what I did:
I added a Service Reference to http://mydomain.gostorego.com/api/v2_soap?wsdl=1, and just adding a service worked fine. Now I created a test class with GetStuff() method, which looks like this:
using ww.Feeds.MagnetoGoService;
public static string GetStuff()
{
MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient s = new MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient();
var login = s.login("username here", "key here");
return login.ToString();
}
When I run the program I get an error in first line saying:
Could not find default endpoint element that references contract 'MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Any ideas what this may be? Do I have to set something up in my Magento Go settings? Or maybe using Magento Go is not allowing API access?
Thanks a lot.
Forget SOAP with c# you will pull your hair out. Download Charls Cook's xml-rpc api libary for c# and use the xml-rpc method. You won't get all the snazzy intellisense but at least it will work. There's also c# solution from ez.newsletter they released with Cook's library demonstrating how to use 80% of the magento api calls.
Cook's library xml-rpc.net
http://www.xml-rpc.net/
ez.newsletter solution
http://code.google.com/p/csharlibformagexmlrpcapi/
If anyone ever has problems with this, my solution was this:
I used the reference in one project, but I actually called the class and had main program in another project. You need your Service reference to be in each project wherever you're using it. That fixed it! Alternatively you can create a new BasicHttpBinding() and putt all the options from app.config/web.config into that binder, then you don't need to reference to Service everywhere. I hope that helps!

Is there an up-to-date c# sample for the Amazon product API?

I'm trying to create a small application that interacts with the Product API of Amazon (get prices of articles, and so on)
Unfortunately all the C# samples for the interaction with the Amazon WCF service I've found so far are outdated.
I know that Amazon decided that each service call must be signed with a personal accessKeyId and secretKey, so all minimal code samples that are older than 2009 (I think they made the change in 2009) are useless. The official Amazon documentation is useless to me as well, as it does not provide necessary information.
I've also googled two tutorial on how to access the API, and following these only result in no search results for any search tearm or simply null.
Is there an up-to-date, working, minimal sample somewhere available?
So, I finally found the solution, based on a comment posted here: http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx
This is also the URL, where I downloaded the code I made working.
I didn't pass my "Your unique Associates ID", which I didn't even had until just now. You can get it here: https://affiliate-program.amazon.com/
Add
itemSearch.AssociateTag = "YourAssociateID";
before amazonClient.ItemSearch(itemSearch).
Works like a charm
I have found a up-to-date project, the code is available on github
Nager.AmazonProductAdvertising
nuget
PM> install-package Nager.AmazonProductAdvertising
Example
var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US, "YourAssociateID");
var result = await client.GetItemsAsync("B0037X9N5U");
if the solution above still won't work.
try this one.. (i use microsoft visual studio 2010)
download the sample code on http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx
we need to update service references, make little change at app.config, program.cs, and reference.cs.
app.config:
(1.) appSettings tag;
assign accessKeyId and secretKey value,
add
<add key="associateTag" value="yourAssociateTag" />.
(2.) behaviours tag -> endpointBehaviors tag -> behaviour tag -> signingBehavior tag;
assign accessKeyId and secretKey value.
(3.) bindings tag -> basicHttpBinding tag; (optional)
delete binding tag except AWSECommerceServiceBindingNoTransport
and AWSECommerceServiceBindingTransport.
(4.) client tag;
delete endpoint tag except AWSECommerceServiceBindingTransport.
program.cs:
add itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; before ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);
reference.cs: (open file in service references folder using visual studio)
change private ImageSet[][] imageSetsField; to private ImageSet[] imageSetsField;
change public ImageSet[][] ImageSets {...} to public ImageSet[] ImageSets {...}
finally we can run our program and it will work. good luck..
nb: there will be 1 warning (invalid child element signing behaviour), i think we can ignore it, or if you have any solution please share.. ^^v..

c# client application can't consume tomtom connect webservice

I have to write a windows application in c# which application is able to consume said webservice.
I am using VS2010 with .Net 4
I added the service reference and the code compiles without any error, but when i run it i get a ProtocolException with the text:
The content type "multipart/related; type="application/xop+xml";
boundary="----=_Part_0_159582014.1283501395804";
start="";
start-info="application/soap+xml"" of the response does not match the
binding (application/soap+xml; charset=utf-8)
When i try it with a VB sample provided by the developers of the webservice everything works fine.
Im totally lost here, googled since yesterday, came up with nothing... Anyone knows whats the problem there?
Ok finally figured it out.
You need to manually edit the app.config file of your application and change all occurences of "textMessageEncoding" to "motmMessageEncoding" that will do the trick
no motmMessageEncoding -> mtomMessageEncoding
you need to make sure that your application supports MTOM. This
requires a change to your app.config. More details can be found here:
http://www.tomtomwork.com/en/webfleet/connect/blog.xml - scroll down
to the section "Updated Visual Basic example now uses SOAP, too"
Try adding a Web Reference rather than a Service Reference and see if that makes any difference. When you select Add Service Reference, click "Advanced..." then "Add Web Reference..." to bring up the old style reference screen.

Categories

Resources