Link to home
Start Free TrialLog in
Avatar of Peter Chan
Peter ChanFlag for Hong Kong

asked on

Which directive to use

Hi,
I get this
Error    7    The type or namespace name 'ExchangeServiceBinding' could not be found (are you missing a using directive or an assembly reference?)    C:\App4\App4\Default.aspx.cs    32    33    App4

due to this line

        static void CreateEmail(ExchangeServiceBinding esb)

Open in new window


which directive should I use for it?
Avatar of gt2847c
gt2847c
Flag of United States of America image

The error is telling you that the compiler doesn't know what the object "ExchangeServiceBinding" is.  The error message is asking if you left out a DLL reference or did not add a "using" directive in your source file.

The using directive at the top of a C# file defines a shortcut for object naming:

For Example, the DateTime object fully qualified is System.DateTime.  If, at the top of your C# file, you specify:
using System;

Open in new window

You are able to use DateTime without the 'System.' prefix.  If you didn't have the using System; directive you would have to fully qualify it as System.DateTime or you would get the error you listed above.

Alternatively, if you are attempting to reference an object that is not part of the standard set of DLLs that are automatically provided for you at compile time, the compiler will be unable to locate the object you are referencing (ExchangeServiceBinding in this case) and will emit that error.

Best I'm able to tell from what snippet you provided, you may not have generated the Web Service Proxy for the Exchange Web Service, in which case you'd get that error.  These two pages may be of assistance:

Setting Up the ExchangeServiceBinding Proxy Class
Creating a Proxy Reference By Using Visual Studio 2005 or Visual Studio 2008
Avatar of Peter Chan

ASKER

Which directive should I use to avoid the problem?
Did you add a reference in your project to the Exchange Web Service Assembly?

Did you add
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;

Open in new window

Thanks.
I am using VS 2013 and I am not able to choose

Microsoft.Exchange

in that.
Did you create the Web Service Reference for the Exchange Server?

Right click your project name in the Solution Explorer.
Select "Add Service Reference"
Click the Advanced button below the Namespace: textbox
Click the Add Web Reference... button at the bottom left
In the URL, fill in the details for your Exchange Server (https://myserver.mydomain.com/EWS/Exchange.asmx)
Fill in any credential prompts it may pop up.
Fill in the name in "Web reference name:" - this will be the name you reference in your code.

If you specify say, "Exchange" in the web reference name, then add
using Exchange;

Open in new window

that may do what you are looking for.
Many thanks. what to choose next, below?

mail.my-friend.co

is what I've put in the MX record and my Exchange server is working fine.
t616.png
Sorry, I get this
t617.png
Are you sure the URL you provided is an Exchange 2010 or later server?  If not, it won't work.
Yes, I am using Exchange 2010.
Try "https://mail.myfriend.co/EWS/Exchange.asmx" in a browser and see if you get anything.  If you get an error or nothing, then there may be a problem with the server you're attempting to connect to.
Yes, I get this below. But

mail.my-friend.co

is the one I put to my MX record and my Exchange server is working fine.
t618.png
Given the error message from your browser, either that front end server is restricting your access or something else may be wrong.  See what you get with this:

https://mail.my-friend.co/owa
I also get the same problem to go to
https://mail.my-friend.co/owa

but it is fine to go to this
https://localhost/owa
If localhost works, try this in your browser and see what you get:

https://localhost/EWS/Exchange.asmx
Thanks. is it fine with the attached?
t619.png
You might want to change the "Web reference name" in that  dialog to something more descriptive than "localhost" as the object will be referenced by that name.  Other than that, it should create the proxy you are trying to reference with your code.  If you want to reference it by the short names, you'll need to add a "using" statement with the name you specify in the "Web reference name".
Sorry, how about I get the attached with that?
t620.png
Several things... First, it appears you're using a self-signed certificate, which is OK for development but not really what you want for production (something to keep in mind for later).  Second, you're referencing the server by localhost rather than the name of the server which would appear to be WIN-AIGPMD763AL.  Since the name localhost is not the same as WIN-AIGPMD763AL the security check on the SSL certificate is letting you know of the mismatch.  That error is to warn you in case you think you're going to say your banking site and someone has hijacked it to go somewhere else.  In this case, since it's your server, its not a problem.  Third, WIN-AIGPMD763AL appears to be the automatically created name Windows server uses when you create a new server.  Did you intend to leave it that way?  Last item, if you are planning on others using your server by the name mail.my-friend.co, all of those attempting to use your server are going to get a similar error message telling them that the certificate was issued to WIN-AIGPMD763AL and not mail.my-friend.co.
Then how to correct it and ensure no similar message later on?
I'll try to address them point by point...

Self-signed certificates will always give you some form of error on a browser as they are not signed by a "trusted" authority.  Self-signed certs are typically intended to give you a working development environment without having to pay for a cert.  If you want a certificate that doesn't get flagged by browsers, you'll need to get a certificate signed by a recognized certificate authority (Entrust, Go Daddy, etc).  Here's a web page that lists  the authorities Microsoft distributes in their trusted root CA list

The last three items are somewhat interrelated.  In the dialog box, you should reference the server based on the expected server name rather than localhost.  Localhost will only work on the server itself.  If you use a fully qualified domain name (mail.my-friend.co), the code should work anywhere you can resolve that name.  Since you tried the fully qualified name unsuccessfully in the earlier steps, that means the DNS server your server is referencing is not able to resolve mail.my-friend.co back to your server.  That could be several causes for that:

- The DNS server is unable to resolve the name mail.my-friend.co - to fix it, add the name to the DNS server with the appropriate IP address (if you're using private address space, see the next point)

- The IP address it does resolve to is an external address and you are using private address space behind a firewall or router - you would either have to have an internal DNS server that can resolve the name for you to an internal address (split-DNS) or have the firewall or router be able to reroute the external address back to your server.  Split-DNS is the most common solution.

The server name is a done deal at this point.  I did a quick check and what I found on Microsoft's various sites state that changing the name of an existing Exchange server is a no-go.  They say the method to change the name goes like:  Uninstall Exchange, change the server name, re-install Exchange.  Alternatively, build another Exchange server with the name you wanted.  

The last item can be fixed several ways.  The typical method is to use the name you desire (mail.my-friend.co) as the name on the certificate signing request you send to the certificate authority to sign.  Other ways to do it would be to have a certificate that allows multiple names or works for the entire domain (*.my-friend.co).  Those options are often dependent on the certificate type and the costs for those certs vary.
Many thanks. should I ask for a certificate to

mail.my-friend.co

from Godaddy? I have only public IP address to the server.
SOLUTION
Avatar of gt2847c
gt2847c
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
which is the insurance policy?
Network Solutions (for example) calls it their Guarantee.  Effectively, it is saying that if a breach of your site happens due to a problem with their certificate, they will compensate your customers up to the limit of the guarantee.  GoDaddy has a guarantee specified in slightly different terms.  The limits are dependent on things like how carefully the issuing Certificate Authority checks the ownership of the domain and how much you pay them for the certificate.  As to how much this means in a court of law, I have no real idea, you'll have to consult a lawyer on that...

Upon thinking about it, if your site isn't very tightly (an provably) secured, the guarantee probably isn't worth a lot...
but I should ask for a certificate from Godaddy, right?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many thanks. which company is giving the cheapest certificate?
Thanks. Do you think a

StartSSL

will resolve my problem?
Having a certificate signed by a trusted authority will make the warning messages go away if that's what you are asking.
But there are several kinds of certificate? Is it to choose

StartSSL

? Thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So I should have Class 3 certificate, right?
That answer is dependent on what you're doing with the site.  It is a judgement call you will need to make.
Can I say "Class 2" can be fine to use, if it is for the site of a private comany?
That would probably be sufficient.