Request failing when I try to send mail to Exchange Server using Exchange Web Services - exchange-server

My code to send mail
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("shiva#shiva.com","pwd");
service.setCredentials(credentials);
service.setUrl(new URI("C:/shiva/Services.asmx"));
EmailMessage msg = new EmailMessage(service);
msg.setSubject("Hello world!");
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
msg.getToRecipients().add("shiva#shiva.com");
msg.send();
I'm getting following error when I ran above code
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Protocol C isn't supported for service request.
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74).
.
.
.
.
Caused by: microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException: Protocol C isn't supported for service request.
at microsoft.exchange.webservices.data.core.ExchangeServiceBase.prepareHttpWebRequestForUrl(ExchangeServiceBase.java:322).
.
.
.
Please help me.

The problem is that you don't point to the URI where your Exchange Web Services (EWS) instance is hosted. Instead your just pointing to the location in the file-system:
service.setUrl(new URI("C:/shiva/Services.asmx"));
So the URI-class tries to interpret C:/ as a protocol which won't work in this situation.
What you'll have to do is the following: Host your EWS-instance on a web server (usually Microsoft IIS in this case. I think you'll need a Windows Server with having set up the required server roles etc.). And let your code point to that URI instead:
service.setUrl(new URI("http://localhost:1234/someWhere/Services.asmx"));

Related

How to fix "The remote name could not be resolved"

I've created asp.net web-api , In the controller I try to call an external URL to send sms(the sms URL I get from the sms provider company )
When I try to call the controller I get this error
"The remote name could not be resolved"
This error only happened on the server ,On the localhost it's working fine
I am using Azure hosting
I tried to add some code to the webconfig
<defaultProxy enabled="true" useDefaultCredentials="true">
I also tried to call the sms URL in a different way
HttpClient client = new HttpClient();
response = client.GetAsync(urlParameters);
I've read some solutions about allowing access for the external link(SMS) on firewall and DNS of the server but it's already configured on azure server
Here is my code
string webAddress = "http://----------------";
string SomeData = System.Text.Encoding.Default.GetString((new
System.Net.WebClient()).DownloadData(webAddress));
I want my web api to send the sms without any error on the server side
Finally ,I solved the problem by replacing the SMS provider URL by their IP Address.
Here is an example of my solution :
Ex : http://123.123.123.123:12345/TEST/Para?i1=

Jersey client with multi domain uri

I am using Jersey Client API to talk to REST server.
Client is having problem in connecting to URL with multiple sub-domains.
EX : https://domain1.domain2.abc.com.
This throws 503 service unavailable.
i trusted all the certs and bypassed host name verification.
Even with HttpsUrlConnection API i get the same 503 error.
But when i hit the same URL with CURL that works fine.
I see the Client API works well with https://domain2.optum.com.
Is there any restriction for Jersey Client (HttpsUrlConnection)API with sub domain names in the URL?

JavaPNS via Apache Web Proxy

My push java app is behind a web proxy. I used below code to set proxy:
ProxyManager.setProxy("", "");
After executed, I got:
javapns.communication.exceptions.CommunicationException: Communication exception: java.io.IOException: Unable to tunnel through. Proxy returns "HTTP/1.1 403 Proxy Error"
Please guide me how to solve this issue.
If there is a username and password required for the proxy, then you also need to set the proxyAuthorization of the ProxyManager.
To encode the username and password, you can use the existing encodeProxyAuthorization method of the ProxyManager:
String encodeProxyAuthorization = ProxyManager.encodeProxyAuthorization(username, password);
ProxyManager.setProxyAuthorization(encodeProxyAuthorization);

How to Configure web service client endpoint url?

We have a situation, our interface partner is calling our web service dynamically by calling our WSDL and consume web methods by using the endpoint defined in the WSDL.
Here, the problem is - As we are using reverse proxy server, the actual web service is hosted in different content server and have URL rewrite rule configured in proxy server to redirect the request to real content server. Our interface partner is successfully consumed our WSDL by using the given reverse proxy URL, but the WSDL is having the real content server URL and our interface partner is not having access to it.
They can change the endpoint url in their proxy class and consume the web service via the reverse proxy URL; unfortunately, they are using some common framework to dynamically build the end point from the received WSDL. So our client could not consume our web service.
Is there any way to determine the client's endpoint url in web service? Thanks in advance.
open wsdl file in browser. save as on local system with .wsdl extension. in client code give url of local file instead of server address as given below.
url = new URL("file:/C:/apps/Services.wsdl");

Get the URI the MPNS to returns to the push client when creating a notification channel Windows Phone 7

/*Get the URI that the Microsoft Push Notification Service returns to the Push Client when creating a notification channel.
Normally, a web service would listen for URIs coming from the web client and maintain a list of URIs to send
notifications out to. */
string subscriptionUri = TextBoxUri.Text.ToString();
Further information on how the pushclient would then sync the URI with a webservice lacks in the description given on MSDN.
So, does anyone know how to make my app send its URI to the MPNS using the push notification client of the Windows Phone, iso having to manually copy-paste them into my web application?
Greetz GP
See MSDN Windows Phone Code Samples at:
http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx
The following code snippet from the 'sdkToastNotificationCS' example show a possible location to store the uri or send to your webservice:
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
// Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
e.ChannelUri.ToString()));
// Instead of showing the URI in a message box, POST to your web service
});
}
Execute an HTTP POST request to send the URI and an identifier for you push user. Receive this POST data on your web service and store the user/URI so you can push notifications to that user from your web service.
You just need an endpoint on your server that the app can send the PNS uri (and any other relevant information) to.

Resources